CONTINUE STATEMENT

CONTINUE STATEMENT 

In Python, the continue statement is used to skip the remaining statements within a loop iteration and move on to the next iteration. When a continue statement is encountered, the current iteration is immediately terminated, and the program jumps to the beginning of the loop for the next iteration.

Here's the general syntax of the continue statement in Python:

SYNTAX:

while condition: # code block if condition: continue # more code

In the while loop example, the loop continues to execute as long as the given condition is true. However, when the if statement's condition is met, the continue statement is executed, and the remaining code in the current iteration is skipped. The program then moves to the next iteration of the loop.

SYNTAX:

for item in sequence: # code block if condition: continue # more code

Similarly, in the for loop example, the loop iterates over a sequence of items. When the if statement's condition is satisfied, the continue statement is triggered, and the remaining code in the current iteration is skipped. The program proceeds to the next iteration.

Here's an example to demonstrate the usage of the continue statement:

CODE:

numbers = [1, 2, 3, 4, 5] for num in numbers: if num == 3: continue print(num)

OUTPUT

# 1 # 2 # 4 # 5



Comments

Popular posts from this blog

Fibonacci Series

COMPARISION EXPRESSION

LOGICAL EXPRESSION