Loop Commands an if ... then ... else loop works to test a variable or expression for true or false (it cannot be for zero or non-zero) in the for block, then excutes the commands in the then block if the test returns a true, or it excutes the commands in the else block if the test returns a false.
The code for a general if ... then ... else loop is as follows:
if(expression to evaluate for true/false)
then{
commands to execute on a true condition
}
else{
commands to execute on a false condition
}
There is a way to use the if statement alone without using
the then or else blocks. The trick in that case is to use
a semicolon after the (expression to evaluate for true/false)
After that, only the next command is treated as being in the then
block, and execution goes on from there, without an else block.
![]()
Home Page | Table of Contents | Introduction | Programming | Extras