♦ Python While Loops
♣ About Python While Loops
While Loop is used to execute the associated code block until the provided expression holds the Boolean value True.Certain Expressions hold the True value for all time, in that case, there is an Infinite While Looping and external signal is required to break the While Loop.
♣ Python While Loops Syntax
Below is a representation of While Loop Syntax in Python.Basic Syntax
while(expression): //code block
expression: statement evaluating to either True or False //code block: program execution until the expression hold value boolean value True Syntax Explanation:
♣ Example1: Python While loop for calculating squares
In this example, While Loop is illustrated. Example
Input:
Output:
♣ Example2: Python While-Break
In this example, Break in While Loop is illustrated. Example
Input:
Output:
♣ Example3: Python While-Continue
In this example, Continue in While Loop is illustrated. Example
Input:
Output: