PYTHON

Control Flow : Iterative Statement


Iterative Statement

If we want to execute a group of statements multiple times then we should go for Iterative statements.  Python Support 2 types of iterative statements:

  1. For loop
  2. While loop

 

For Loop:

To execute some action for every element present sequence then we should go for ‘for’ loop.

https://cdn.programiz.com/sites/tutorial2program/files/forLoop.jpg

  

syntax:

for x in sequence :
	statements

 

While Loop

To execute a group of statements iteratively until some condition false, then we should go for while loop.
 

syntax:

while condition :
	statements

 

Infinite Loop

A loop which keeps executing forever known as Infinite loop.

 

Nested Loop

A loop inside another loop is nothing but a nested loop.

 


PYTHON