Conditional Statements
Conditional statements control conditional branching. The body of a conditional statement is only executed if the value of the expression is nonzero.
If Statement
Syntax
if-statement
:
if (
expression
)
statement
if (
expression
)
statement
else
statement
Example
In this example, if a
is a negative number, its value is set to zero. Otherwise, the value of a
is increased by 1.
You can also have nested branching, like so:
Or concurrent if statements:
Last updated