What are the different control structures in Python?
A control structure is a programming method which affects the flow of the execution of a program. Python provides different control structure to execute a program.
![]() |
Control Statements in Python |
1) Sequential Statement: The statement that executes in a sequential order. i.e. one after the other without any jumps are called sequential statement. A sequential structure is also called a straight line path.
![]() |
Sequential Statement |
2) Selection Statement: Some problem doesn’t solve by performing sequential statement, but they execute if a particular condition is true. There are three selection statements.
i) if statement: if condition is true then it execute the statement. if condition is false, it doesn't execute any statement.
![]() |
if condition |
ii) if-else statement: if condition is true then it executes a statement and in case condition is false it executes other statement.
![]() |
if - else condition |
1) For loop: The for loop statements allow the user to repeat a set of statement multiple number of time. This statement is used when number of loops is known.
Statement - 1
Program -1
Write a program to print ‘Hello Python five time.
![]() |
For Loop in Python |
Program -2
Write a program to print first five natural numbers.
![]() |
For Loop in Python |
Program - 3
Write a program to print even numbers between one to ten.
![]() |
For Loop in Python |
2) While loop: The while loop repeats a block of statements for a given number of times, until the given condition is false. In this loop first the condition is checked and if it is true, the block of statements runs until the condition becomes false.
Syntax of while loop :
while(condition):
Statement – 1
Program - 1
Write a program to add first five natural numbers.
![]() |
While Loop in Python |
No comments:
Post a Comment