VXi VT1529A/B Manual De Usuario

Descargar
Página de 529
Creating and Running Algorithms   219
 
Note that in BASIC the boolean_expression is delimited by the IF and the 
THEN keywords. In 'C', the parentheses delimit the expression. In 'C', 
the ")" is the implied THEN. In BASIC, the END IF keyword terminates a 
multi-line IF. In 'C', the if is terminated at the end of the following statement 
when no else clause is present or at the end of the statement following the 
else clause. Figure 6-6 shows examples of these forms.
Note that in 'C' "else" is part of the closest previous "if" statement. 
So the example:
if( x ) if( y ) z = 1; else z = 2;
executes like:
not like:
if( x ){
if( x ){
if( y ){
if ( y ){
z = 1;
z = 1;
}
}
else{
}
z = 2;
else{
}
z  =  2;
}
}
Simplest form (used often)
Two-line form (not recommended; use
multiple line form instead)
Multiple line form (used often)
Multiple line form with else (used often)
Comments
if(boolean_expression) statement;
if(boolean_expression)
statement;
if(boolean_expression){
statement;
statement;
statement;
}
if(boolean_expression)
{
statement;
statement;
}
else
{
statement;
}
'C' Syntax
Figure 6-5. The If Statement 'C' versus BASIC
IF boolean_expression THEN 
statement
IF boolean_expression THEN
statement
END IF
IF boolean_expression THEN
statement
statement
statement
END IF
IF boolean_expression THEN
statement
statement
ELSE
statement
END IF
BASIC Syntax