xxxxxxxxxx
# Example of continue loop:
for number is range (0,5):
# If the number is 4, skip the rest of the loop and continue from the top.
if number == 4:
continue
print(f"Number is: {number}")
xxxxxxxxxx
## When the program execution reaches a continue statement,
## the program execution immediately jumps back to the start
## of the loop.
while True:
print('Who are you?')
name = input()
if name != 'Joe':
continue
print('Hello, Joe. What is the password? (It is a fish.)')
password = input()
if password == 'swordfish':
break
print('Access granted.')
xxxxxxxxxx
import numpy as np
values=np.arange(0,10)
for value in values:
if value==3:
continue
elif value==8:
print('Eight value')
elif value==9:
break
xxxxxxxxxx
>>> for num in range(2, 10):
if num % 2 == 0:
print("Found an even number", num)
continue
print("Found a number", num)
Found an even number 2
Found a number 3
Found an even number 4
Found a number 5
Found an even number 6
Found a number 7
Found an even number 8
Found a number 9
xxxxxxxxxx
while True:
line = input('Write something: ')
if not line == '': # if the line variable is not empty, run the code block
print(line)
continue # Continues back to the beginning of the while loop
else:
break # if the line variable is empty come out the loop and run the next code
print('End of the program')
xxxxxxxxxx
//Continue makes the code return to the start of a loop
//While break put you after the loop
for letter in 'python': //letter will be p, y, t, h, o, n
if letter == y:
continue //With continue we skip the y
if letter == n:
break //With break we stop the loop at n
print("The letter is :", letter)
/*
Output :
The letter is : p
The letter is : t
The letter is : h
The letter is : o
*/