×

c# · level 1 · unit 5 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

stops a loop early. skips a turn.

Sometimes you find what you need halfway through a loop. break stops the loop straight away, and C# carries on with the first line after it.

continue is gentler. It skips the rest of this turn only, then the loop moves on to the next one, like skipping a song you do not like.

Both usually sit inside an if, so they only happen when a condition is true.

using System;

for (int song = 1; song <= 5; song++)
{
    if (song == 4)
    {
        break;
    }
    Console.WriteLine($"Playing song {song}");
}
Console.WriteLine("Party over!");

break leaves the loop, while continue stays in it and starts the next turn.