Ticker

6/recent/ticker-posts

Looping –while and For loops in Python

 Looping –while and For loops in Python:

Executing or iterating the block of statement until the condition is met is called Looping. There are two types of looping in Python. They are While loop and For loop

While Loop:

While loop is like the ‘If statement’ but in if statement the block will be executed only once but in while the block will be executed or iterated again and again until the condition is true. It is also known as indefinite iteration because it’ll execute until the condition is false.

 

While loop

Single statement while block

Single statement while block in Python


 

For Loop:

Like the while loop, for loop also executes the block of statement repeatedly but the difference is while loop executes undefined number of times and ‘for loop’ executes for a predefined or preset number of times. It is also known as definite iteration.

 

For loop in Python


Post a Comment

0 Comments