Nested if statement, COBOL Programming


 The then and else statement of an IF statement can hold other IF statements. The involved IF statements in their turn may also hold other IF statements. These inclusion of one or more IF statements within the scope of the IF statement is termed as nesting. Note that the most inclusive IF statement should have a terminating period and therefore this statement along with all the included statements is frequently termed as NESTED IF STATEMENT.

As the else phrase in an IF statement is optional, the nested If sentence may have less ELSEs than Ifs. This makes the interpretation of the nested IF sentence quite difficult. The initial step in interpreting such a sentence would be to find out that ELSE belongs to which IF and which are the IFs that do not have the corresponding ELSEs. Once this is completed, the actions specified for the various cases can be recognized easily. To avoid any ambiguity in an interpretation, the COBOL rule is as shown below. 

The nested IF sentence must be examined in the left- to-right manner to encounter each

ELSE in the order of its appearance. As soon as an ELSE is encountered, it should be paired with the instantly preceding IF which has not yet been paired with the other ELSE.

Note that the above rule can also helps in detecting those Ifs for which the ELSE phrase may be absent.

The above rule states how the COBOL compiler will interpret a nested IF sentence. And hence, while writing such a sentence this rule should be applied to verify that the interpretation of the compiler will not be different from what is intended. The illustrations below are used to show how the meaning of a nested IF sentence can be obtained by applying the above rules.


Posted Date: 10/17/2012 2:03:29 AM | Location : United States

Related Discussions:- Nested if statement, Assignment Help, Ask Question on Nested if statement, Get Answer, Expert's Help, Nested if statement Discussions

Write discussion on Nested if statement
Your posts are moderated
Related Questions
I uploaded a file from PC to Mainframe, variable LRCL 256. In my COBOL program I defined it as FD INPUT-FILE LABEL RECORDS ARE OMITTED BLOCK CONTAINS 0 RECORDING MODE

PROGRAM FOR ELECTRICITY BILL: An electricity company supplies electricity to 4 types of customers coded 1, 2, 3 & 4.The rate schedule for customers is shown in one table as

SUBTRACT VERB: The SUBTRACT verb is used to subtract one, or the sum of two or more numbers from one or more numbers and to store the result. The form of the SUBTRACT verb

WRITE STATEMENT: The WRITE Statement verb releases a record in an output file. The syntax for the WRITE statement can be unlike depending on the output device and the medium us

Example of Open statement: Illustration: The OPEN INPUT TRANSACTION, OLD-MASTER OUTPUT NEW-MASTER. The illustration represents that there are two input files named the

PROGRAM FOR INDEXED SEQUENTIAL FILE CREATION (RANDOM MODE): We have to write a program to create an Indexed Sequential File in random mode for Student particulars. Suppose jus

PROGRAM FOR SIMPLE PERFORM: We have to write a program to elaborate simple PERFORM statement Identification division. Program- id.  Perf1. Environment division. Da

Block Size: The normal practice is to group a number of consecutive records to form that is termed as a block or a physical record. The number of records in a block is frequen

FILLER CLAUSE: Consider the statements as shown below: 1)  01    f    pic     x(80)  value    all "-". This statement origins a line of 80 characters filled with "-"

MOVE CORRESPONDING: It is frequently required to move some of the data items of one group to some other data items in the other group. If the names of the equivalent data item