Flow control in Python

Purushoth Anandaraja
3 min readJul 18, 2020

--

In this article, I will be discussing flow control in the python language. as an overview, I will be discussing IF, ELSE condition ELIF conditions, and loops (for, while loops).

If, Else and Elif conditions

If, Else Condition

Generally in if conditions we define a condition under certain terms to happen if the certain condition is not met the else part comes to action where the else part occurs.

Basic IF Else condition in python.
A flow chart representation of the If Else condition.

Elif Condition

In Elif condition, we define multiple conditions to execute so that if one condition is not met one of the other conditions will be executed.

Basic Elif Condition
A flow chart representation of the Elif condition.

Loops (while, for, continue, break, range)

while loop

With the while loop, we can execute a set of statements as long as a condition is true.

Basic while loop
Flowchart for while loop in Python

For loop

The for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects. I will discuss what is a list and tuple in another blog.

Basic for loop
Flowchart for For loop in Python

Continue keyword

The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.

continue keyword
Flowchart for continue keyword in Python

Break keyword

The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop. If the break statement is inside a nested loop (loop inside another loop), the break statement will terminate the innermost loop.

Break keyword in Python
Flowchart for break keyword in Python

Range keyword

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.

Range keyword in Python

I hope that’s all for this article now. let’s discuss in another article about Lists, tuples, and Range. Until then cheers to all.!!!

--

--

No responses yet