Loops

Loops repeat a block while a boolean condition holds, with explicit statements for advancing or terminating iteration.

while

A while loop evaluates its condition before every iteration. Its body does not run when the initial condition is false.

while (remaining > 0)
{
    Process(remaining);
    remaining--;
}

for

A for loop keeps initialization, condition and update expressions together. The initializer runs once, the condition is checked before each iteration, and the update runs after the body.

for (int i = 0; i < count; i++)
{
    Process(i);
}

continue

continue skips the rest of the current iteration. In a for loop, execution proceeds to the update expression before checking the condition again.

for (int i = 0; i < count; i++)
{
    if (ShouldSkip(i))
        continue;

    Process(i);
}

break

break exits the nearest enclosing loop and continues with the statement following that loop.

while (true)
{
    if (IsComplete())
        break;

    ProcessNext();
}