python for loop continue to next iteration

Being a programmer we may face a situation we have to continue to next iteration in python for loop here in this section we are going to explore the syntax of python for loop continue statement.

Syntac

for LOOP:

   # add something.

   if condition true:
      continue    # continue here
    
    print("Loop value without  condition true")
    

suppose we have a have for loop like below to print all the number between 90 and 100

for number in range(90,100):
    
   print('Number is ' + str(number))

OutPut

Number is 91
Number is 92
Number is 93
Number is 94
Number is 95
Number is 96
Number is 97
Number is 98
Number is 99

So next our requirement we have to print only even number between 90 and 100

for number in range(90,100):
   value = number %2

   if value != 0:
      continue    # continue here

   print('Even number is ' + str(number))

OutPut

Even number is 90
Even number is 92
Even number is 94
Even number is 96
Even number is 98

python for loop continue to next iteration

Leave a Reply

Your email address will not be published. Required fields are marked *