MySQL 9.0.0
Source Code Documentation
mysqltest Flow Control Constructs

The syntax for if block looks like this:

if (expr)
{
  command list
}

The syntax for while block looks like this:

while (expr)
{
  command list
}

An expression result is true if nonzero, false if zero. If the expression begins with !, the sense of the test is reversed.

If the expression is a string that does not begin with a numeric digit (possibly preceeded by a plus or minus sign), it evaluates as true if non-empty. Any white space is ignored in this case, so a string consisting of only white space is false.

There is no provision for else with if.

For a while loop, make sure that the loop includes some exit condition that eventually occurs. This can be done by writing expr so that it becomes false at some point.

The allowable syntax for expr is $var_name, !$var_name, integer, or `query`.

The expression can also be a simple comparison, where the left hand side must be a variable, and the right hand side can be string or any type valid for the single expression except the negated variable. The supported operators are ==, !=, <, <=, > and >=. Only the first two may be used if the right hand side does not evaluate to an integer. With ==, strings must match exactly.

If you use a string on the right hand side of the comparison, it does not have to be quoted even if it contains spaces. It may optionally be enclosed in single or double quotation marks which will then be stripped off before comparison. This is in contrast to let statements, where quoting is not stripped.

Examples of the expression syntax with and without comparisons (only the header shown):

while ($counter<5) ...
if ($value == 'No such row') ...
if ($slave_count != $master_count) ...
if ($counter < `SELECT 10`) ...
if (-1) ...
if (20) ...
if (`SELECT 1`) ...
if(! $cnt) ...

The opening { (curly brace) must be separated from the preceding ) (right parenthesis) by whitespace, such as a space or a line break.

Variable references that occur within `query` are expanded before the query is sent to the server for execution.