
Fill in
Skip and Stop
Two little keywords give you more control inside any loop:
continue: skip the rest of this round and jump to the next one.break: stop the whole loop right now.
for n in range(1, 8):
if n == 2:
continue # skip 2
if n == 5:
break # stop at 5
print(n)
This prints 1, 3 and 4. When n is 2, continue skips the
print. When n is 5, break ends the loop before printing.
Assignment
Pip is searching rocks numbered 1 to 19 for treasure.
- Rocks whose number is a multiple of 3 are too heavy to lift, fill the first blank so they are skipped.
- The treasure is under rock 11, fill the second blank so the search stops right after the treasure message.
Pip is searching rocks numbered 1 to 19 for treasure.
- Rocks whose number is a multiple of 3 are too heavy to lift, fill the first blank so they are skipped.
- The treasure is under rock 11, fill the second blank so the search stops right after the treasure message.
main.py Python sleeping
Press Run to try your code, then Check to test it.