User`s manual

42 digi.com Language
4.18.3 Branching
The goto statement is the simplest form of a branching statement. Coupled with a statement label, it sim-
ply transfers program control to the labeled statement.
The colon at the end of the labels is required. In general, the use of the goto statement is discouraged in
structured programming.
The next simplest form of branching is the if statement. The simple form of the if statement tests a con-
dition and executes a statement or compound statement if the condition expression is true (non-zero). The
program will ignore the if body when the condition is false (zero).
A more complex form of the if statement tests the condition and executes certain statements if the expres-
sion is true, and executes another group of statements when the expression is false.
The fullest form of the if statements produces a succession of tests.
The program evaluates the first expression (expr
1
). If that proves false, it tries the second expression
(expr
2
), and continues testing until it finds a true expression, an else clause, or the end of the if state-
ment. An else clause is optional. Without an else clause, an if/else if statement that finds no true
condition will execute none of the controlled statements.
some statements
abc:
other statements
goto abc;
...
more statements
goto def;
...
def:
more statements
if( expression ){
some statement(s)
}
if( expression ){
some statement(s) // if true
}else{
some statement(s) // if false
}
if( expr
1
){
some statements
}else if( expr
2
){
some statements
}else if( expr
3
){
some statements
...
}else{
some statements
}