You are on page 1of 12

CONTROL

STRUCTURES IN
PYTHON 3
Sequential control
Default mode.

Sequential execution of code statements ( one line after another),


like following a sequence of instructions
Sequential control
Selection control
Use for decisions, branching. Choosing between 2 or more
alternative paths.

CONDITION

True False
Types of Selection control
Selection statement: If statement

-The “if statement” is the simplest of the selection control


Types of Selection control
Selection statement: If – else statement

-It consist of an if statement that execute a block of statement


whether it is true or false.
Types of Selection control
Selection statement: If - elif - else statement

-It consist of 2 or more if statement


Repetition
- Causes a statement or set of statements to execute repeatedly

- The program execute a statement repeatedly until it reach the


set condition.

- Repetition statements fall into two general categories; while


loops and for loops. Although it is possible to write a loop as a
while loop (or every loop as a for loop). This is not good idea
While statement
The Boolean expression (condition) in this example is: x <5
The expression has a value of true or false (1 or 0)
If the condition is true,
the intended statements are executed,
otherwise, the statements are skipped.
For statement
For loop using range()
For val in sequence:
Body of for:
Do-while statement

You might also like