Home > Python > Introduction to Python

Ch. 1.6 While Loop

Chapters Index
Program 1

While Loop

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

Understanding While Loops in Python

Initialize a Variable:

The variable i is set to 1.

While Loop:

The loop runs as long as condition is True i.e. in current case i is less than or equal to 5.

Print Statement:

It prints the current iteration number (e.g., "This is iteration number 1").

Increment:

The value of i increases by 1 in each iteration to prevent an infinite loop.

Program 2

While Loop

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 3

While Loop

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 4

While Loop

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.