3 Top Python Loop Controls With Syntax Explained

Python supports three types of Loop statements. Those are While, For and Nested Loop. Loops also called iterations.

In my previous posts, I have added an example of how to Calculate the Area of Circle and Factorial ‘n’.

In this post, I have explained the loop control statements that present in Python and their syntax.

For example, to display (factorial n), you need a logic to execute as a loop and to print factorial n values.

Python Loop Control Statements

  1. For Loop
  2. While Loop
  3. Nested Loop

Python While Loop Flow Chart

python while loop

While Loop Enters When Test Condition is True

  • Infinite Loops:

    A loop becomes an infinite loop if a condition never becomes FALSE.

    The programmer must be cautious when using while loops because of the possibility that the test_condition never evaluates to a FALSE value

Python WHILE Loop Syntax

while test_condition:
        body of loop

Python FOR Loop Flow Chart

Python While Loop

It checks items in the List. If Found, executes.

Python FOR Loop Syntax

for val in sequence:

Syntax for Nested WHILE and FOR Loops

Python Nested While Loop

while test_condition:
      while test_condition:

Python Nested For Loop

for val in sequence:
        for val in sequence:

In the above nested loop syntax of both WHILE and FOR, you can observe a Loop within another Loop.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.