Learn
Battleship!
A Real Win

Almost there! We can play Battleship!, but you’ll notice that when you win, if you haven’t already guessed 4 times, the program asks you to enter another guess. What we’d rather have happen is for the program to end—it’s no fun guessing if you know you’ve already sunk the Battleship!

We can use the break command to get out of a for loop.

Instructions

1.

Add a break under the win condition to end the loop after a win.

Folder Icon

Take this course for free

Already have an account?