Learn Create Your Own Split Screen

Next Page

Now we're going to meet a new type of loop.

But first, we all know about while-loops, right?
while (alien_count > 0) { update_the_canvas(); show_score(); } display_game_over();
The loop keeps running as long as alien_count is greater than zero.

Once it drops to zero or below, the loop finishes and we'll display the game over message.

If, at the outset, the alien count isn't greater than zero then the loop won't get executed even once, and the program will go straight to displaying the game over message, without ever once having updated the canvas or showing the score.

That's just how while-loops work. But sometimes that can be a bit inconvenient and awkward.