1 of 15

CONTROL STRUCTURE IN PYTHON PROGRAMMING

PART III

Prepared By

P. K. Nakhate

2 of 15

CONTROL FLOW STATEMENTS,

The flow control statements are divided into three categories

  • Conditional statements
  • Iterative statements.
  • Transfer statements

3 of 15

CONDITIONAL STATEMENTS�

In Python, condition statements act depending on whether a given condition is true or false. You can execute different blocks of codes depending on the outcome of a condition. Condition statements always evaluate to either True or False.

There are three types of conditional statements.

  1. if statement
  2. if-else
  3. if-elif-else
  4. nested if-else

4 of 15

ITERATIVE STATEMENTS

In Python, iterative statements allow us to execute a block of code repeatedly as long as the condition is True. We also call it a loop statements.

Python provides us the following two loop statement to perform some actions repeatedly

  1. for loop
  2. while loop

TRANSFER STATEMENTS

In Python, transfer statements are used to alter the program’s way of execution in a certain manner. For this purpose, we use three types of transfer statements.

  • break statement
  • continue statement
  • pass statements

5 of 15

IF STATEMENT IN PYTHON�

In control statements, The if statement is the simplest form. It takes a condition and

evaluates to either True or False.

If the condition is True, then the True block of code will be executed,

and if the condition is False, then the block of code is skipped, and The controller moves to the next line

Syntax of the if statement

if condition:

statement 1

statement 2

statement n

6 of 15

IF – ELSE STATEMENT

7 of 15

CHAIN MULTIPLE IF STATEMENT IN PYTHON�

8 of 15

NESTED IF-ELSE STATEMENT

9 of 15

SINGLE STATEMENT SUITES�

10 of 15

FOR LOOP IN PYTHON

Using for loop, we can iterate any sequence or iterable variable. The sequence can be string, listdictionaryset, or tuple.

11 of 15

While loop in Python

In Python, The while loop statement repeatedly executes a code block while a particular condition is true.

In a while-loop, every time the condition is checked at the beginning of the loop, and if it is true, then the loop’s body gets executed. When the condition became False, the controller comes out of the block.

12 of 15

Break Statement in Python

13 of 15

Continue statement in python

14 of 15

Pass statement in Python

15 of 15

Thank You