Skip to main content
GameDev.net gamedev.net
🔒 Locked

Continue

Started by Anaton May 3, 2006 at 10:55 AM 3 replies 1.5k views
Original Post
Anaton
Anaton
The college class I'm taking for C asked this question in the textbook; not homework book and I don't understand what it's saying or what the result will be. Here is a simple way to test the effect of a continue statement in the body of a for loop. What is printed?

for (putchar('1'); putchar('2'); putchar('3')) {
 putchar('4');
 continue;
 putchar('5');
}



I tried inserting this into a program to see what it would output and couldn't get it to work. What am I doing wrong or missing here? *edited for typos*
Anaton
Sneftel
Sneftel
It looks like you've accidentally replaced a ) with a 0.
Tera_Dragon
Tera_Dragon
I just tried it and it first prints 1, then repeatedly prints 234234... It never reaches 5 because the continue statement causes the loop to move onto the next loop early. It continuously loops because putchar('2') must be returning a non-null int.
____________________________________________________________Programmers Resource Central
bakery2k1
bakery2k1
It actually prints '1', then repeats '243', not '234'. This is because the loop body is evaluated before the "increment" expression.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.