07-02-2007 3:39 PM
pls tell how many times this loop will executes...
n=2.
do n times.
write n.
n=n+1.
enddo.
07-02-2007 3:45 PM
07-02-2007 3:42 PM
Hi,
This is a infinite loop.
To stop the loop give condition like
do n times.
write n.
n=n+1.
<b>If n = 20.
EXIT.
Endif.</b>
enddo.
Reward if helpful.
07-02-2007 3:44 PM
this will execute only 2 times, just tested that
before the DO loop value of n is 2 , so it will loop only 2 times..
Output will be 2 and 3
07-02-2007 3:45 PM
07-02-2007 3:46 PM
It is an infinite loop because you are telling it to execute 'n' number of times, but you are incrementing 'n' within each loop pass, so it will just go on and on
I stand corrected, it does only execute twice
Message was edited by:
showthousand
07-02-2007 3:51 PM
hi
Whats is type for n?.
In its integer then it will execute infinity times.
because ur adding n = N + 1. So it will goto short dumb.
Regards
Ravi
07-02-2007 3:54 PM
Hi Ramna,
This will execute<b> only 2 times</b> and the output will be
2
3
It will always consider the value of <b>N times</b> when the DO...ENDDO before starting up of execution but it wont consider the values even it is updated in the DO...ENDDO.
Thanks,
Vinay
07-02-2007 4:22 PM
Hi Ramna,
Actual it is not an infinite loop but you made it as infinite loop.
Reason:
Your looping on n. initial it n has value 2 .
once the loop encounterd then you have incremented n. so it mean n beacme 3. so the loop has to turn 3 times now. this process will continue in this way so it became infinite loop
Regards,
Lisa
07-02-2007 4:29 PM
the do control structure does not accept any change of the value n with
in the loop.if n contains a value less than or equal to zero the statement block will not be executed..so ur out put will be 2 and 3 though its type is numc or interger or a if float 2.0000000e00 3.0000000e00