The if continue statement is used in both whiles and for loops in Python. A continue statement does not execute all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.
Python if continue examples
Simple example code. If using the continue statement in Python loops then it returns the control to the beginning of the loop.
for i in range(5): if i == 3: # skips if i is 3 continue print(i)
Another Example code
If continue statement with NumPy in Python.
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
Output: Eight value
Python while continue
If 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?') password = input() if password == '123456': break print('Access granted.')
Do comment if you have any doubts and suggestions on this Pytho it statement with the continue keyword.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.