Back to questions
JuniorTheoryCommon
What does the program print?
for (int i = 1; i <= 5; i++)
{
if (i == 3)
{
continue;
}
Console.Write(i);
}1245
- Expecting
12:continuedoes not leave the loop the waybreakdoes; it ends only the current iteration, and the loop goes on withi = 4. - Expecting the program to hang: in a
forloop the stepi++runs aftercontinuetoo; a loop hangs when it is awhilethat changes its variable aftercontinue.
- What does the program print if
continueis replaced withbreak? - How would you rewrite the loop without
continueso that the output stays the same?