The most famous decision making statement in all language is ‘IF’. The syntax of IF statement is given below: IF can be coded without any ELSE statement. THEN is a noise word and it is optional.
If ORs & ANDs are used in the same sentence, ANDs are evaluated first from left to right, followed by ORs. This rule can be overridden by using parentheses.
The permitted relation conditions are =, <, >, <=, >=, <>
CONTINUE is no operation statement. The control is just passed to next STATEMENT. NEXT SENTENCE passes the control to the next SENTENCE. If you forgot the difference between statement and sentence, refer the first page.
It is advised to use END-IF, explicit scope terminator for the IF statements than period, implicit scope terminator.
IF condition1 AND condition2 THEN
Statement-Block-1
ELSE
IF condition3 THEN
CONTINUE
ELSE
IF condition4 THEN
Statement-Block-2
ELSE
NEXT SENTENCE
END-IF
END-IF
END-IF
Statement-Block-2 will be executed only when condition 1, 2 and 4 are TRUE and condition 3 is FALSE.
Implied operand: In compound conditions, it is not always necessary to specify both operands for each condition. IF TOTAL=7 or 8 is acceptable. Here TOTAL=8 is implied operation.
No comments:
Post a Comment