Control Structures in Python
Control Structures
The commands learned so far followed a linear sequence, until the last command
Is executed. Control structures allow the commands to be executed under certain
Condition.
• Conditional statement
• Loops
• Functions
Conditional statement
if statement
if else statement
elif statement
A conditional statement in Python is a programming construct
that allows you to make decisions based on certain conditions or
criteria. It helps you control the flow of your program by executing
different blocks of code depending on whether a given condition
is true or false.
If Statement
Flowchart of if statement
if else statement
Nested if…else statement
If( condition 1){
Command or statement if condition 1 true
}else if(condition 2) {
Command or statement if condition 2 true
}
……
}else{statement when none of above is true}
Loops
Loops are used in programming to repeat a specific block of code.
Types of loop:
● For loop
● While loop
● Repeat loop
For
For loopLoop
Used to iterate over a vector.