IAJWDDIY
asked on
For loop
Hi,
How is the following loop interpreted?
Thank you.
for (i=56;i>0;){
How is the following loop interpreted?
Thank you.
for (i=56;i>0;){
'i' is initialized to 56 and the loop is executed as long as 'i' does not drop below '1'. However, since the 'loop expression' (as in "for( [init-expr]; [cond-expr]; [loop-expr] )") does not change 'i', it has to be altered inside the loop body to meet that criteria.
Loop starts with i equal to 56
Continues to loop while i is greater than 0
Continues to loop while i is greater than 0
https://www.experts-exchange.com/questions/22033122/for-statement-question.html for statement question
Need to reduce i, else you have infinite loop. This will reduce it by one on each iteration of the loop:
for (i=56;i>0;i--){
for (i=56;i>0;i--){
>>Need to reduce i
What was unclear about "However, since the 'loop expression' [...] does not change 'i', it has to be altered inside the loop body to meet that criteria."?
What was unclear about "However, since the 'loop expression' [...] does not change 'i', it has to be altered inside the loop body to meet that criteria."?
ASKER
So if there is a statement like:
a=z[i-] ; b=z[i-].....
inside the loop would this reduce?
Thanks
a=z[i-] ; b=z[i-].....
inside the loop would this reduce?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
>>What was unclear
Nothing wrong with more clarity, adding the words "infinite loop', and giving an i-- option. : )
Nothing wrong with more clarity, adding the words "infinite loop', and giving an i-- option. : )
IAJWDDIY, it's almost hidden away, but there's a "Split points" link in open questions at the bottom ;)
Then, as long as i is greater than 0
execute the following compound statement.