BRANCHING STATEMENT CONTENT 1. PERFORM STATEMENT 1.1 SIMPLE PERFORM STATEMENT 1.2 PERFROM…TIMES STATEMENT 1.3 IN-LINE PERFORM STATEMENT 1.4 PERFORM….UNTIL STATEMENT 1.5 PERFORM….VARYING.... UNTIL STATEMENT 1.6 PERFORM… VARYING…UNTIL…AFTER….UNTIL STATEMENT 2. GO TO STATEMENT 2.1 SIMPLE GO TO STATEMENT 2.2 GO TO ….. DEPENDING ON STATEMENT 3. COMPARISON AMONG PERFORM AND GO TO STATEMENT 4. THROUGH / THRU KEYWORD. 5. WITH TEST BEFORE / AFTER 1. PERFORM STATEMENT 1.1 SIMPLE PERFORM STATEMENT Syntax: PERFORM procedure-name-1. While executin executing g simple simple PERFOR PERFORM M statem statement, ent, control control transfe transferre rred d to the first first Working: While statement of the specified procedure/ paragraph. After the execution of the paragraph, control return back to the statement following the PERFORM statement in the main paragraph.
1.2 PERFORM ….TIMES STATEMENT Syntax: PERFORM procedure-name-1 {integer-1/ identifier-1} TIMES.
PERFORM statement, control transferred transferred to the first statement statement Working: While executing the PERFORM of the specified specified procedure/ paragraph. paragraph. That procedure/ paragraph paragraph will execute integer-1 (using current value of identifier-1) times. After the execution, control return back to the statement following the PERFORM statement in the main paragraph. • Identifier-1 should have a positive integral value. • If identifier-1 value is negative the paragraph will not execute and control goes to the next statement in sequence. • If the value of integer is zero then paragraph will not execute. If integer value is one, then paragraph paragraph will will execute once. once.
1.3 IN-LINE PERFORM STATEMENT Syntax: PERFORM PERFORM UNTIL condition.
For eg: PERFORM UNTIL FIELD>10 ADD 1 TO …… MOVE…… COMPUTE…… ………………… END PERFORM.
No paragraph paragraph name follows follows PERFOR PERFORM. M. Loop through this code until FIELD >10
Terminates the scope of the loop
When a paragraph name is omitted, the statements to be executed are coded in the same paragraph paragraph as the the PERFORM PERFORM statement. statement. Such Such a structure structure is called called an in-line PERFOR PERFORM M statement. An in-line PERFORM is terminated with END_PERFORM. No period period s may may be used used between between PEROFORM PEROFORM and END-PE END-PERFORM RFORM within within an • in-line PERFORM statement. Lengthy in-line PERFORM statement can be very difficult to understand and maintain. • We can use in-line PERFORM anywhere you use PERFORM •
1.4 1.4 PERFORM …UNTIL STATEMENT Syntax: PERFORM procedure-name-1 UNTIL condition. Working: While While executi executing ng simple simple PERFOR PERFORM M statem statement, ent, control control transfe transferre rred d to the first first statement statement of the specified specified procedure/ paragraph. paragraph. That procedure/ procedure/ paragraph paragraph will execute until condition becomes true. 1) First First control control will check check the conditio condition; n; if the conditi condition on is false, false, control control transfer transferred red to specified paragraph/ procedure. 2) After After the execution execution of the paragr paragraph aph control control will will return return back to the main paragra paragraph ph again it will check the condition. 3) If the condition condition is false false again control control transferr transferred ed to the specified specified paragra paragraph. ph. 4) This process process will will continue continue until until condition condition becomes becomes true. true. 5) If the condit conditio ion n is true, true, contr control ol will not pass to spec specif ifie ied d para paragr grap aph h and it will will not execute and the statement following the PERFORM statement in the main paragraph will execute. • It is useful to change the subscript value in the one dimensional table. • If we want to execute some paragraphs we can use this perform …until statement.
1.5 PERFORM….VARYING.....UNTIL STATEMENT Syntax: PERFORM procedure-name-1 VARYING identifier-1 FROM initial-value BY increment-factor/ decrement-factor UNTIL condition. • Here we are combining the initialization and increment / decrement factor of the identifier in one line. • For incrementing, increment factor value should be positive and for decrementing, decrement factor value should be negative. Working: steps are 1. Compiler set the value of identifier-1 to initial-value. 2. Compiler check the condition 3. If the condition is false, compiler executes the specified paragraph. 4. After the execution of the specified paragraph, control transfer to increment part; here the identifier-1 adds increment-factor to its previous value. 5.After increment control transfer to condition part, it will check the condition; if it is false, then control transfer to specified paragraph. 6.Control transfer to the first statement of the paragraph; after the execution, again the identifier-1 will increment by increment-factor. (it will continue until condition becomes true) 7.If the condition becomes true; statement following the perform statement will execute.
1.6 PERFORM… VARYING…UNTIL…AFTER….UNTIL STATEMENT Syntax: PERFORM procedure-name-1 VARYING identifier-1 FROM initial-value-1 BY increment-factor-1/ decrement-factor-1 UNTIL condition-1 AFTER identifier-2 FROM initial-value-2 BY increment-factor-2/ decrement-factor-2 UNTIL condition-2. • Here we are combining the initialization and increment / decrement factor of the identifier-1 and identifier-2 in one line. • For incrementing, increment factor value should be positive and for decrementing, decrement factor value should be negative. • Here both the conditions are false, the specified paragraph will execute. • It is a nested looping statement; so it is useful in multidimensional arrays.
Working: steps are 1. Compiler se set the the value of of id identifier-1 to to in initial-value-1. 2. Compiler checks the condition-1. 3. If the cond condit itio ionn-1 1 is is fal false se,, con contr trol ol trans ransfe ferr to to AFT AFTER ER part part,, set set iden identtifie ifierr-2 2 to to intial-value-2. 4. Afte fter the init nitializatio ation, n, cont ontrol transf nsfer to condit nditio ionn-2. 2. 5. If the the condit nditio ionn-2 2 is is fal falsse, co contr ntrol transf nsfer to to sp specif cified par parag agrraph. 6. Aft After that hat con contr trol ol trans ransfe ferr to to inc incre reme ment nt part part of iden identi tifi fier er-2 -2;; ie. ie. Ident dentif ifie ierr-2 2 add addss increment- factor-2 to its previous content. 7. Control checks the condition-2; 8. If it is false, co control transfer to specified paragraph. 9. If the cond condit itio ionn-2 2 is is fal false se,, con contr trol ol trans ransfe ferr to to inc incre reme ment nt part part of ident dentif ifie ierr-1. 1. i.e i.e identifier-1 adds increment-factor-1 to its previous content 10. Control checks the condition-1 11. 11. If the the con condi diti tion on-1 -1 is fals false, e, cont contro roll tra trans nsfe ferr to to AFT AFTER ER part part,, set set iden identi tifi fier er-2 -2 to intial-value-2. 12. Afte fter the the ini inittializatio ation, n, con conttrol transf nsfer to to co condit nditio ionn-2. 2. 13. If the cond condit itio ionn-2 2 is is fal false se,, con contr trol ol trans ransfe ferr to to spe speci cifi fied ed parag aragra raph ph.. 14. 14. Afte Afterr tha thatt con contr trol ol tran transf sfer er to incr increm emen entt par partt of of ide ident ntif ifie ierr-2; 2; ie. ie. Ide Ident ntif ifie ierr-2 2 add addss increment- factor-2 to its previous content. 15. 15. Cont Contro roll chec checks ks the the con condi diti tion on-2 -2;; it will will cont contin inue ue unt until cond condit itio ionn-1 1 bec becom omes es true true.. 2. GO TO STATEMENT 2.1 SIMPLE GO TO STATEMENT Syntax: GO TO procedure-name-1 [, procedure-name-2]….. • Here control will transfer to the specified procedure unconditionally. • In simple GO TO statement, control will transfer to the specified procedure. After the execution of the procedure, control will transfer to the remaining paragraphs. Control will not return to the main paragraph.
2.2 GO TO ….. DEPENDING ON STATEMENT Syntax: GO TO procedure-name-1 [, procedure-name-2]….., procedure-name-n DEPENDING ON identifier Working: depending on the value of identifier, control transfer to the procedure. For eg: if the identifier = 1, procedure-name-1 will execute, if the identifier = 2, procedure-name-2 will execute, if the identifier = 3, procedure-name-3 will execute etc…..
3. COMPARISON AMONG PERFORM AND GO TO STATEMENT GO TO STATEMENT GO TO is always unconditional GO TO is a jump statement In GO TO statement, control will transfer to the specified paragraph and control will pass to to the remaining remaining paragra paragraphs phs also also Control will not return back to main paragraph paragraph In GO TO, proced procedure ure-nam -namee is mandat mandatory ory In GO TO, always the specified paragraph will execute.
PERFORM STATEMENT PERFORM can be conditional or unconditional PERFORM is a looping statement In PERFORM statement, control will transfer to the specified paragraph and control will not pass to the remaining paragraphs Control will return to the main paragraph.
In PERFOR PERFORM, M, proced procedureure-name name is optiona optionall In conditional PERFORM, the condition is false, the paragraph will execute. If it is true, it will not.
4. THROUGH / THRU KEYWORD •
If we want to execute a number of procedures continuously then we can use THROUGH / THRU keyword. For eg: PERFORM P2 THRU P4. Control will transfer to P2, after that P3 and last P4 will execute. After the execution of P2, P3 and P4 control will return back to the main paragraph.
5. WITH TEST BEFORE / AFTER
WITH TEST BEFORE: in this case first compiler will check the condition before the execution of the paragraph. • WITH TEST AFTER: in this case first compiler will execute the paragraph after that control will transfer to condition part. •
The modified Syntaxes are PERFORM procedure-name-1 [{THROUGH / THRU} procedure-name-2]. PERFORM procedure-name-1 [{THROUGH / THRU} procedure-name-2] {integer-1/ identifier-1} TIMES. PERFORM procedure-name-1 [{THROUGH / THRU} procedure-name-2] [WITH TEST {AFTER / BEFORE}] UNTIL condition-1. PERFORM procedure-name-1 [{THROUGH / THRU} procedure-name-2] [WITH TEST {AFTER / BEFORE}] VARYING identifier-1 FROM initial-value-1 BY increment-factor1/ decrement-factor-1 UNTIL condition-1 AFTER identifier-2 FROM initial-value-2 BY increment-factor-2/ decrement-factor-2 UNTIL condition-2.