---
title: "How to Use For, While, and Nested Loops in Python"
description: "Python top loop control statements of FOR, WHILE, and Nested Loops explained with flowchart and syntax."
url: https://srinimf.com/2019/10/24/python-loop-control-statements-real-syntax/
date: 2019-10-24
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2019/10/pexels-photo-4966178.jpeg?fit=1880%2C1253&ssl=1
categories: ["Python"]
tags: ["Python tips and tricks", "Python While Loop Syntax"]
type: post
lang: en
---

# How to Use For, While, and Nested Loops in Python

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](https://srinimf.com/2021/11/15/bash-how-to-calculate-sum-after-reading-file/) the [Area of Circle](https://www.biganalytics.me/2019/01/calculate-circle-area-python.html)and Factorial ‘n’.

## FOR, WHILE and NESTED [LOOPS in Python](https://srinimf.com/2022/05/30/amazing-fact-why-cant-we-use-for-in-python-lambda/) and their[syntax.](https://whatis.techtarget.com/definition/syntax)

For example, to display [(factorial n](https://www.biganalytics.me/2019/01/python-factorial-logic.html)), you need a logic to execute as a loop and to print factorial n values.

## Python Loops

1. WHILE Loop
2. Nested Loop
3. For Loop

## 1. While Loop Flow Chart

![python while loop](https://i0.wp.com/srinimf.com/wp-content/uploads/2019/10/python-while-loop.png?resize=365%2C286&ssl=1)

## While Loop Enters When Test Condition is True

**Python WHILE Loop Syntax**

```
while test_condition:
        body of loop
```

**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

## 2. Nested WHILE and FOR Loops

**Python Nested While Loop**

```
while test_condition:
      while test_condition:
      statement(s)
      statement(s)
```

**Python Nested For Loop **

```
for val in sequence:
        for val in sequence:
        statement(s)
        statement(s)
```

In the above, WHILE and FOR nested-loops, you can find a Loop within the Loop.

## 3. FOR Loop Flow Chart

![Python While Loop](https://i0.wp.com/srinimf.com/wp-content/uploads/2019/10/python-for-loop.png?resize=365%2C286&ssl=1)

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

**Python FOR Loop Syntax**

```
for val in sequence:
        statement(s)
```

**Related Posts**

- [The Amazing Fact Why Can’t We use Loops in Python Lambda](https://srinimf.com/2022/05/30/amazing-fact-why-cant-we-use-for-in-python-lambda/)DateMay 30, 2022
- [Exclusive Loops Vs Iterators in Python](https://srinimf.com/2021/10/25/exclusive-loops-vs-iterator-object-in-python/)DateOctober 25, 2021
- [How to Find Sum of Series in Python](https://srinimf.com/2021/11/22/how-to-find-sum-of-series-in-python/)DateNovember 22, 2021

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2019%2F10%2F24%2Fpython-loop-control-statements-real-syntax%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2019%2F10%2Fpexels-photo-4966178.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Use%20For%2C%20While%2C%20and%20Nested%20Loops%20in%20Python)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2019/10/24/python-loop-control-statements-real-syntax/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2019/10/24/python-loop-control-statements-real-syntax/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2019/10/24/python-loop-control-statements-real-syntax/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2019/10/24/python-loop-control-statements-real-syntax/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Use%20For%2C%20While%2C%20and%20Nested%20Loops%20in%20Python&body=https%3A%2F%2Fsrinimf.com%2F2019%2F10%2F24%2Fpython-loop-control-statements-real-syntax%2F&share=email)
-

### Like this:

Like Loading…
