Basic Loops - 'continue' and 'pass'
In Python, loops are powerful tools that let you repeat blocks of code. While loops are essential, controlling their flow using mechanisms like 'pass' and 'continue' can make your code more efficient and readable.
a. The 'continue' statement:
The 'continue' statement skips the current iteration of the loop and moves to the next one.
Code
for i in range(5): if i == 2: continue print(i)
Output
0 1 3 4
b. The 'pass' statement:
The 'pass' statement is a null operation; nothing happens when it executes. It's typically used as a placeholder.
Code
for i in range(3): if i == 1: pass else: print(i)
Output
0 2