Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

logic

Former Member
0 Kudos

pls tell how many times this loop will executes...

n=2.

do n times.

write n.

n=n+1.

enddo.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

2 times ur output will be 2 & 3

8 REPLIES 8

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

2 times ur output will be 2 & 3

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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