Game Development Reference
In-Depth Information
Program Flow Control Statements
The important program flow control statements for the OpenGL ES 2.0 shader language follow.
for loop:
To use a
for
loop, initialize the counter value before starting the loop;
execute the loop, if the expression evaluates to true; at the end of the loop, update
the counter value; and repeat the loop, if the expression in the
for
loop evaluates
to true.
for(Initial counter value;
Expression to be evaluated;
Counter increment/decrement value)
{
// Statements to be executed.
}
while loop:
Execute the statements in the
while
loop, as long as the expression to
be evaluated is true.
while( Expression to evaluate )
{
// Statement to be executed
}
if statement:
If the expression evaluates to true, then the statements within the
if
block are executed.
if (Expression to evaluate )
{
// Statements to execute
}
if else
statement:
Execute the statements in the
if
block; if expression evaluates
to
true else
, execute the statements in the
else
block.
if (Expression to evaluate)
{
// Statement to execute if expression is true
}
else
{
// Statement to execute if expression is false
}