View previous topic :: View next topic
|
Author |
Message |
dipti
New User
Joined: 07 Jan 2006 Posts: 4
|
|
|
|
perform varying i from -2 by 1 until i>2
display 'A'
add 2 to i
end-perform.
how many times 'A' will be displayed.
i tried this program, but it is displaying 'A' only one time why it is showing 'A' only one time. |
|
Back to top |
|
|
manjinder
New User
Joined: 04 Dec 2005 Posts: 45 Location: pune
|
|
|
|
it wont show A once it will show A 2 times first for ->-2
second for -> 1 |
|
Back to top |
|
|
rajesh_1183
Active User
Joined: 24 Nov 2005 Posts: 121 Location: Tadepalligudem
|
|
|
|
it will display A for 5 times...
*** looping variables(ie; i) will not be modified inside the loop...
correct me if i am wrong.....
Thanks,
Rajesh. |
|
Back to top |
|
|
gowtham_1982 Warnings : 1 Active User
Joined: 02 Dec 2005 Posts: 109
|
|
|
|
rajesh_1183 wrote: |
it will display A for 5 times...
*** looping variables(ie; i) will not be modified inside the loop...
correct me if i am wrong.....
Thanks,
Rajesh. |
hai rajesh,
we can modify the subscript or index within a loop. it is possible.
and the solution to the query, the display will be 2 times.
corrections welcomed..
gowtham |
|
Back to top |
|
|
rajesh_1183
Active User
Joined: 24 Nov 2005 Posts: 121 Location: Tadepalligudem
|
|
|
|
hi gowtham,
But dipti hasn't metioned that it is a subscript ot index variable.......
Thanks,
Rajesh |
|
Back to top |
|
|
gowtham_1982 Warnings : 1 Active User
Joined: 02 Dec 2005 Posts: 109
|
|
|
|
rajesh_1183 wrote: |
hi gowtham,
But dipti hasn't metioned that it is a subscript ot index variable.......
Thanks,
Rajesh |
rajesh,
that does not matter. all i wanted to clear was that we can modify the variable depending on which the loope executes, with in the perform loop.
corrections welcomed.
gowtham |
|
Back to top |
|
|
rajesh_1183
Active User
Joined: 24 Nov 2005 Posts: 121 Location: Tadepalligudem
|
|
|
|
Goutham,
In one of the faqs, i read like..we can't modify the looping-variable inside a loop..i am not sure abt this stmt whther it will work for only inline performs or all types of performs......
If it is a subscript or index..we can modify....
Thanks,
rajesh |
|
Back to top |
|
|
vinodmaanju
New User
Joined: 10 May 2005 Posts: 28 Location: Pune
|
|
|
|
I CHKED IT ON MY SYSTEM WITHOUT USING SUBSCRIPT AND INDEX AND I GOT THE RESULT THAT I CAN MODIFY LOOPING VARIABLE IN LOOP. BUT IN CASE OF PERFORM N TIMES WE CAN NOT CHANGE THE EXECUTION OF LOOP.
I USED THIS :
PROCEDURE DIVISION.
PERFORM VARYING C FROM 1 BY 2 UNTIL C > 10
SUBTRACT 1 FROM C
DISPLAY ' C ' C
END-PERFORM.
AND MY LOOP WAS EXECUTED 10 TIMES.
EXAMPLE 2:
PROCEDURE DIVISION.
MOVE 5 TO C.
PERFORM C TIMES
SUBTRACT 1 FROM C
DISPLAY ' C : ' C
END-PERFORM.
STOP RUN.
WILL EXECUTE 5 TIMES AND VALUE OF C WILL GIVE 04,03,02,01,00
IN SATYAM ONE OF MY INTERVIEWERS WHO ASKED ME SAME QUESTION. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi,
It has to be dispaly A twice
I think deepti has given picture clause for i like
01 i pic 9.
it should be
01 i pic s9.
regards,
chandan |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Rajesh said:
Quote: |
But dipti hasn't metioned that it is a subscript ot index variable....... |
If INDEX was used the pgm wouldn't compile.
wouldn't be accepted as a valid COBOL stmt in that context. You must use "set i up by 2". |
|
Back to top |
|
|
pa1chandak Currently Banned New User
Joined: 31 Jan 2006 Posts: 55
|
|
|
|
IF YOU ARE SPECIGING MOVE 2 TO A THEN IT WILL PERFORM THE LOOP 5 TIMES
BUT IF SPECIFY ADD 2 TO A THEN IT SHOULD HAVE PERFORMED THE LOOP 2 TIMES ONLY
IF I AM WRONG SOMEWHERE PLEASE CORRECT ME
THANK YOU
DO SEND ME THE REPLY
PAWAN
09822546416
// THE ONE I LOVE , I SHALL NEVER BLAME // |
|
Back to top |
|
|
sudheer_kumar
New User
Joined: 27 Dec 2005 Posts: 16
|
|
|
|
1)
01 I PIC [b]S9 VALUE 1[/b]
PERFORM VARYING I FROM -2 BY 1 UNTIL I > 2
DISPLAY 'A'
ADD 2 TO I
END-PERFORM.
For the above code , A will be displayed twice. Because for the first time
I=-2 , A is displayed and 2 will be added to I . The value of I becomes zero. For the second time I is increased to 1(I FROM -2 BY 1). The condition will be satisfied and the again A will be displayed.
2)
01 I PIC 9 VALUE 1 ---- > No sign field
PERFORM VARYING I FROM -2 BY 1 UNTIL I > 2
DISPLAY 'A'
ADD 2 TO I
END-PERFORM.
For the above code , A will be displayed only once. Because for the first time the value of I is 2 not -2 since I is not decalred as sign field.
Therefore only once will displayed.
I think dipti has declared I has PIC 9.
Correct me If I am wrong |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Hi Dipti,
A will be displayed 2 times.
Since initially i is -2, A wil be displayed.
then added 2 to i, i now becomes 0, then thru perfrom again added 1 to i
now i is 1, one more A is displayed
add 2+ 1 to i, i becomes 4
end-perform is executed.
ie A is displayed 2 times.
if i is declared without s ( i pic s9), initial value of i will be 0.
only one a will be displayed.
Regards
Aji Cherian |
|
Back to top |
|
|
mijanurit Currently Banned New User
Joined: 26 Aug 2005 Posts: 33 Location: bangalore
|
|
|
|
hi all!
it will show 'A' two times.
because
1.first time control comes to the loop when i's value is -2 and display A.
within loop i's value become 0.
then perform statement itself increament the value of i by 1.
now the value of i become 1.
2. second time control will come to loop and display A.
same thing will happen and i's value will be 4.
now perform condition will not be satisfied.
control will come out of the loop.
thanks and regards
mijanurit |
|
Back to top |
|
|
|