For Loop and While Loop in Python

Document
Image description

For Loop

A for loop is a control flow statement that allows you to execute a block of code repeatedly for a specified number of times. It's particularly useful when you know in advance how many times you want the loop to iterate.

Example:


    for i in range(6):
         print(i)
        

While Loop

A while loop is another control flow statement that executes a block of code repeatedly as long as a certain condition is true. It's useful when you don't know the exact number of iterations in advance.

Example:


    i=0
    while i<11:
     print(9*i)
     i+=1
        
Follow on LinkedIn

Comments

Popular posts from this blog

Recursion In Python

Tkinter and Api

Sets in python