LOOP CONTROL STATEMENT

 LOOP CONTROL STATEMENTS

Loop control statements in Python are used to alter the execution flow within loops. They allow you to control how the loop behaves and when it should terminate or skip iterations. The common loop control statements in Python include:

  1. break statement: It is used to exit the loop prematurely. When encountered, the program jumps out of the loop and continues with the next statement after the loop.
SYNTAX:

while condition: if some_condition: break # rest of the loop code
2.continue statement: It is used to skip the remaining code in the current iteration of the loop and move to the next iterationfor item in sequence
for item in sequence:
    SYNTAX:

if some_condition:
        continue
    # rest of the loop code
  1. pass statement: It is a placeholder statement that does nothing. It is used when a statement is syntactically required but you don't want to execute any code.
SYNTAX:

if condition:
pass # no code to execute else: # code block to be executed
  1. else statement with loops: It is used to define a block of code that executes only when the loop condition becomes false. The else block is skipped if the loop is terminated by a break statement
SYNTAX:

while condition:
    # loop code
else:
    # code to execute when the loop condition becomes false

Comments

Popular posts from this blog

Fibonacci Series

COMPARISION EXPRESSION

LOGICAL EXPRESSION