3. ⮚ Control structure identifies the
sequence of execution of statements
or code flow in python
⮚ It can be:
⮚ Sequential Execution
⮚ Conditional Execution
⮚ Iterative Execution
What is Control Structure?
Image source :
https://opensource.c
om/
5. Conditional Execution : if Statement
⮚ One – way decision statement
⮚ Syntax:
⮚ Example:
if <expression> :
#when condition is true
6. Conditional Execution : if..else Statement
⮚ Two – way decision statement
⮚ Syntax:
⮚ Example:
if <expression> :
#when condition is true
else:
# when condition is false
13. Iterative Execution: while statement
⮚ Indefinite loop : keep going until a logical
condition becomes False
⮚ Syntax:
⮚ Example:
while <condition> :
#when condition is true repeat
14. Breaking the loop
⮚ To end the current loop in between, use ‘ break ’ statement
⮚ Example:
15. Skipping the iteration (Continue)
⮚ To end the current iteration and start the next iteration of loop, use
continue statement
⮚ Example:
16. while with else statement
⮚ If while loop ended normally without break call, control passes to an
optional else
17. Iterative Execution : for statement
⮚ Definite loop : Repeat for exact number of times
⮚ Syntax:
⮚ Example:
for <iterator_variable> in <range> :
#repeat upto range
18. Iterative Execution : for statement
⮚ If you do need to iterate over a sequence of numbers, the built-in function
range() comes in handy
⮚ range (start, stop, step)
22. Assignment
1. Explain the types control structures
2. Write a program to check number is prime or not
3. Write a program to check the entered number is Armstrong number
or not
4. Differentiate between break and continue
5. Write a PYTHON program that prints 1 2 4 8 16 32 … 2^n