Next: Print statement, Previous: Function/procedure, Up: Syntax [Contents][Index]
The if-else, while- and for-loops constitute the program control statements. These loops can be broken at any stage with the use of the break statement. As of now, the conditions which control the logic is evaluated ignoring the error with the control variables. Ultimately the goal is to provide a language feature to specify a significance level and the conditional statements return true if the error on the evaluated value is within the significance level, else return false.
The syntax for the if-else statement is:
if (condition) if-body-statement; or if (condition) if-body-statement else else-body-statement;
The if-body-statement and the else-body-statement can be any valid compound or simple statement. In case of a simple statement, the terminating semi-colon is necessary.
The syntax for the while-loop is:
while (condition) body-statement
The body-statement can be either a simple or a compound statement and in case it is a simple statement, the terminating semi-colon defines the end of the loop.
The syntax for the for-loop is:
for (init;condition;incr) body-statement
where init is a comma (',') separate list of simple statements for initializing the loop variables. E.g. init can be i=0,j=0,k=0. condition is a simple, single statement while incr is a list of comma separated statement(s). The body-statement can be any valid simple or compound statement. init statements are executed first followed by the condition statement. If the result of the condition statement is non-zero (logical true), the body-statements, the incr statement(s) and the condition statements are executed in a sequence till the result of the condition statement is zero (logical false). E.g. following is a valid for-loop with 3 loop-variables, only one of which is checked in the condition:
for (i=0,j=0,k=0;i<10;i=i+1,j=j+1;k=k+1) print "i= ",i," j= ",j," k= ",k,"\n";
Next: Print statement, Previous: Function/procedure, Up: Syntax [Contents][Index]