Sunday, August 2, 2009

Continue statement help?

Can someone help me again. I'm trying to find out what this continue statement will display on the screen, but I keep getting this error:





fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\reggie\my documents\visual studio 2005\projects\continue statement\continue statement\continue statement.cpp(5)' was matched





this is the program that I wrote:





#include %26lt;stdio.h%26gt;


#include %26lt;stdafx.h%26gt;





int main (void)


{


for (putchar('1'); putchar('2'); putchar('3')){


putchar('4');


continue;


putchar('5');


}





Please tell me where I went wrong.

Continue statement help?
You should always make sure that you indent all of your code, this makes it much easier to spot when there is an imbalance of braces. Add an extra '}' and your syntax error will be solved.





You didn't ask about this, but the 'for' loop is not set up to work properly there. The middle component is supposed to be the test condition that causes the loop to terminate or keep repeating. The 'putchar' function is not a test and it will return the same result just about every time, which means that your loop will either keep going forever or stop sooner than you expected depending on what putchar('2') returns.





I'm sure you'll find out or already know what the 'continue' does in that little program.
Reply:You need another } for the for loop.


No comments:

Post a Comment