Thursday, 4 September 2014

COBOL IF END-IF Statement.

A conditional statement is one that performs operation depending on the existence of some condition. In COBOL, such statements generally begin with the word IF and are called IF-THEN-ELSE or selection structures. Refer below figure for more details:

IF END-IF Statement.
COBOL IF END-IF Statement.

Format :    IF condition [THEN] imperative statements 
                   ELSE imperative statements
Imperative statement as apposed to a conditional statement, is one that performs an operation regardless of any existing conditions. 
NESTED IFs : The THEN and ELSE parts of an IF statement can contain other IF statements. The included IF statements in turn may also contain other IF statements. Such inclusion of one or more IF statements within the scope of an IF statement is called nesting of IF statements.
Format :  IF condition [THEN] imperative statements 
             ELSE imperative statements
                     IF Condition
                         imperative statements
Example :
COBOL IF END-IF Statement Example.

Note : Always indent statements with the IF instruction to make programs easier to read ans debug. 

No comments:

Post a comment