Python While Loop

Loop

Loop is used to repeat a set of statementsfor example if you want to print counting from 1 to 100 then you will never want to write print statement 100 times so, loop makes it easy to print with just few lines of code.


There are mainly two types of loop in python :

  1. While loop
  2. For loop

While Loop

Using while loop, a set of statement is executed continued until the condition becomes false.




Break Statement

The break statement is used to break or stop the loop, even if the condition is true.




Pass Statement

The pass statement is used to avoid the error even if the loop is empty. It doesn't break the loop.




Continue Statement

The continue statement is used to skip the current iteration and continue with the next one.




Conditional Statement

Here, you can use conditional statement "if elif and else" inside while loop.




Else Statement

when the condition is no longer true, then you can execute a code using else statement.




List Element

Now, you can also print elements of list using 'while loop'.




Create a list of cars and print all the element of list using while loop.

Comments