Provides conditional execution of code based on boolean expressions.
Evaluates boolean expression
cond-1, and if true executes the block of code
body-1. If
cond-1 is false, then
cond-2 is evaluated (if present) and if true
body-2 will be executed. This is repeated for each
elseif condition in order until one of the conditions is found to be true. If none of the conditionals are true, then the
else-body will be executed.
The
else and
elseif clauses are optional. Any number of
elseif clauses may be specified, but only one
else, which must be the last clause in the sequence. Any of the bodys may be empty.
If an
if expression contains an
else clause and the body of every clause produces a value or ends with a statement that does not return (e.g.
throw or
error or proc declared to return
never-returns), then the
if expression will produce the value of the body for the branch that is executed. In this case, the
if expression may be used in places where values are expected such as the right hand side of an assignment or as an argument to a function.
For examples and a more detailed discussion of
if and other conditional forms in Curl see
Conditional Constructs in The Developers Guide.