Your fundamental confusion I think has to do with the fact that commenting out a statement removes the statement entirely. It does not make a "do nothing" statement that is then the body of the if
.
However, I think there is also a confusion expressed about what continue
does. A good way to understand this is to reduce it to something simpler.
Suppose you have
for (int i = 0; i < 10; i++)
{
if ((i % 2) == 0)
continue;
Console.Write (i + " ");
}
Let's reduce this to a simpler program, in the sense that for
is complicated and while
is less complicated. Your program fragment is the same as:
{
int i = 0;
while (i < 10)
{
if ((i % 2) == 0)
goto DoTheLoopIncrement;
Console.Write (i + " ");
DoTheLoopIncrement:
++i;
}
}
Which is the same as:
{
int i = 0;
DoTheLoopTest:
if (i < 10)
goto DoTheLoopBody;
else
goto DoneTheLoop;
DoTheLoopBody:
{
if ((i % 2) == 0)
goto DoTheLoopIncrement;
Console.Write (i + " ");
DoTheLoopIncrement:
++i;
goto DoTheLoopTest;
}
}
DoneTheLoop:
...
Notice how much longer and harder to read the "goto" version is. That's why we use while
and for
. But you must understand that this is precisely what while
and for
and continue
are doing in order to make sense of their control flows. They are just a pleasant way of writing a goto
.
Now: do you understand what break
means? Break is just a pleasant way to write goto DoneTheLoop
.