Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Can we use loop in cobol language

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
nikhil.tak8

New User


Joined: 12 Jan 2007
Posts: 2
Location: delhi

PostPosted: Wed Jan 17, 2007 12:49 am    Post subject: Can we use loop in cobol language
Reply with quote

i just wanted to know that can we use loop in cobol language
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jan 17, 2007 12:57 am    Post subject:
Reply with quote

Hello,

Yes, we use "loop" in COBOL.

In your manual, look up "PERFORM . . . WHILE" and "PERFORM. . . UNTIL".
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Jan 17, 2007 12:58 am    Post subject: Re: loop in cobol
Reply with quote

nikhil.tak8,

I'm not 100 % sure what you questions is.

I see two posibilities:

1 - What can cause a loop in a COBOL Program

or

2 - How can you use loops in a COBOL Program

Can you please clarify for us.

Thanks,
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Sun Jan 21, 2007 9:50 pm    Post subject: Re: Can we use loop in cobol language
Reply with quote

nikhil.tak8 wrote:
i just wanted to know that can we use loop in cobol language

---------------------------------------------------------------------
answer:-
Yes the loop structure is possible in cobol,for example in loop structure use in two dimension table programme.
OR IN SIMPLE PROGRAMME IS ALSO CODED USING IF ELSE
FOR EXAMPLE
IF COND
ELSE
MOVE A TO B
IF B=4
THEN (IMPERATIVE STATMENT)
ELSE
DISPLAY"THIS IS NOT 4,5"
IF B=6
THEN IMERATIVE ST.
ELSE
DISPLAY "THIS NORANGE"
END-IF
END-IF
END-IF.
----------------------------------------------------------------------
AND IN TWO DIMENTION
ID DIVISION
PROGRAM ID. EDFF.
DATA DIVISION
W-S SECTION
01 SCHOOL.
02 NAME PIC X(5) OCCURS 2 TIMES INDEXED BY I
03 MARKS PIC 9(2) OCCURS 3 TIMES INDEXED BY J
PROCEDURE DIVISION.
ACCEPT I
PERFORN VARYING WITH TEST BEFORE VARYING I FROM
- FROM 1 BY 1 UNTIL I>5
ACCEPT (I,J)
PERFORM VARYING WITH TEST AFTER
- VARYINH J FROM 1 BY 1 UNTIL J>3
END-PERFORM
END-PERFORM.
------------------------------------------------------------
CORREC ME I AM WRONGE
-SACHIN BORASE
PUNE
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Jan 21, 2007 10:06 pm    Post subject:
Reply with quote

Hello,

IF - THEN - ELSE is not a loop.

A loop may iterate through a process multiple times before processing continues. IF/THEN/ELSE is a single construct and is only executed once - then processing continues.
Back to top
View user's profile Send private message
Rajesh Melwani

New User


Joined: 10 Jan 2007
Posts: 3
Location: Mumbai

PostPosted: Mon Jan 22, 2007 5:29 pm    Post subject:
Reply with quote

Looping is possible in most of programming languages, and Cobol also has it.

There are multiple ways of looping in COBOL. Few are listed below:
1. GO TO
2. PERFORM UNTIL
3. PERFORM VARYING

Though GO TO's are NOT used these days and are not recommended.
"IF" is a programming construct and as correctly said above, is NOT a LOOP.

Hope it helps.
Back to top
View user's profile Send private message
dnreddy

New User


Joined: 08 Dec 2006
Posts: 8
Location: chennai

PostPosted: Tue Jan 30, 2007 12:58 pm    Post subject:
Reply with quote

Hi

The COBOL allwos looping,PERFORM is uesd for loop.
folling diffrent example for PERFORM

Performing one procedure (Format 1):


PERFORM PROC-A.



ITEMB = Asssssssss

Performing a range of procedures (Format 1):


PERFORM PROC-A THRU PROC-B.



ITEMB = AssssssssA

Performing a range of procedures (Format 2):


PERFORM PROC-A THRU PROC-C
3 TIMES.



ITEMB = AsCsEssssE
ITEMC = 07

Performing a range of procedures (Format 4):


PERFORM PROC-A THRU PROC-B
VARYING ITEMC FROM 1 BY 1
UNTIL ITEMC > 5.



ITEMB = ABCDEssssE
ITEMC = 06

Testing the UNTIL condition after execution (Format 4):


PERFORM PROC-A THRU PROC-B
TEST AFTER
VARYING ITEMC FROM 1 BY 1
UNTIL ITEMC > 5.



ITEMB = ABCDEFsssF
ITEMC = 06

Performing a range of procedures varying a data item by a negative amount (Format 4):


PERFORM PROC-A THRU PROC-B
VARYING ITEMC FROM ITEMD BY -1
UNTIL ITEMC < ITEME.



ITEMB = sssDEFGssD
ITEMC = 03

In-line PERFORM (Format 4):


PERFORM
VARYING ITEMC FROM 1 BY 2
UNTIL ITEMC > 7
MOVE CHARA (ITEMC) TO CHARB (ITEMC)
MOVE CHARA (ITEMC) TO CHARB (ITEMC + 3)
END-PERFORM.



ITEMB = AsCAECGEsG

Varying two data items (Format 4):


PERFORM PROC-D
VARYING ITEMC FROM 1 BY 1 UNTIL ITEMC > 4
AFTER ITEMD FROM 1 BY 1 UNTIL ITEMD > 5.



ITEMG (1) = 01s02s03s04s05s
ITEMG (2) = 02s04s06s08s10s
ITEMG (3) = 03s06s09s12s15s
ITEMG (4) = 04s08s12s16s20s

-----------------------
Narendra reddy
Chennai
Back to top
View user's profile Send private message
chtrisa

New User


Joined: 19 Dec 2006
Posts: 12
Location: chennai

PostPosted: Tue Jan 30, 2007 2:14 pm    Post subject:
Reply with quote

hello

COBOL allows looping.just see this link

http://publib.boulder.ibm.com/infocenter/pdthelp/v1r1/index.jsp?topic=/com.ibm.debugtooluaf5.doc/vrmu1mst02.htm
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Tue Jan 30, 2007 3:05 pm    Post subject:
Reply with quote

good answer chtrisa!

;)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts StreamWeaver language reference chetanambi Compuware & Other Tools 1 Wed Jul 05, 2017 12:50 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us