SlideShare a Scribd company logo
4
Most read
5
Most read
7
Most read
Control statements
in
python
CONTROL
sTATEMENTs
Defination:
Control statements are the statements
which control or change the flow of
execution.
The following are the control
statements available in python:
 If statements
 If….else statement
 If….elif…else statement
 While loop
 For loop
 Break statement
 Continue statement
 Pass statement
 Assert statement
 Return statement
The if statement:
This statement is used to execute one or more
statement depending up on whether a condition is true
or not.
Syntax: if condition:
statements
code: num=1 output:
if num==1: one
print(“one”)
The if…else statement:
This statement execute the group of statements when a
condition is true, otherwise it will execute the else
statement.
Syntax: if condition:
statements
else:
statements
code: x=int(input(“enter the value”))
if x%2==0:
print(“even”)
else:
print(“odd”)
The if..elif..else statement:
The if..elif..else statement is used to execute the block of
statements among more than two condition.
Syntax: if condition1: code: num=5
statements1 if num==0:
elif condition2: print(“zero value”)
statement2 elif num<0:
elif condition3: print(“negative”)
statement3 else:
else: print(“positive”)
statement4
The while loop:
The while loop is useful to execute a group of
statement several times repeatedly depending up
on whether a condition is True or False.
Syntax: while condition:
statements
code: x=1
while x<=10:
print(“x=”,x)
x+=1
The for loop:
The for loop is useful to iterate over the
elements of a sequence.it means ,the for loop
can be used to execute a group of statement
repeatedly depending upon the number of
element in the sequence
syntax: for var in sequence:
statements
code: str=“hello”
for ch in str:
print(ch)
The break statement:
The break statement can be used Inside the a for loop or while
loop to come out of the loop. When ‘break’ is executed, the
python interpreter jumps out of the loop to process the next
statement in the program.
Syntax: while/for condition:
statements
code: x=0
while x<=10:
print(“x=”,x)
if x==5:
break
The continue statements:
The continue statement is used within loop to skip the
some part of the current iteration and move in to the next
iteration.
Syntax: while/for condition:
if condition:
continue
code: x=0
while x<=10:
print(“x=”,x)
if x==5:
continue
The pass statement:
The pass statement does not do anything. It is used with
‘if’ statement or inside the loop to represent no
operation. We use pass statement when we need a
statement syntactically but we do not want to do any
operation.
The assert statement:
The assert statement is useful to check if a particular
condition is fulfilled or not.
Syntax: assert expression, message
code: x=int(input(“enter the value greater than 0=”))
assert x>0, “wrong input entered”
print(“you entered:” ,x)
The return statement:
A return statement is used to end the execution
of the function call and “return”
the result.
Syntax: def fun()
statements
return expression
code: def cube(x):
r=x**3
return r
Thankyou

More Related Content

PPTX
Conditional and control statement
PPTX
CBSE Grade XI - Computer system overview - Lesson 1
PPTX
Python Functions
PPTX
List in Python
PPTX
Object Oriented Programming Using C++
PDF
Python Flow Control
PPSX
Inferential statistics.ppt
PDF
VTU Algorithms Notes CBCS (DAA Notes) by Nithin, VVCE
Conditional and control statement
CBSE Grade XI - Computer system overview - Lesson 1
Python Functions
List in Python
Object Oriented Programming Using C++
Python Flow Control
Inferential statistics.ppt
VTU Algorithms Notes CBCS (DAA Notes) by Nithin, VVCE

What's hot (20)

PPTX
Code Optimization
PPT
15. Transactions in DBMS
PPTX
python conditional statement.pptx
PDF
Python Decision Making
PDF
Python programming : Control statements
PPTX
Thread priorities
PPTX
Looping statement in python
PPTX
Functions in Python
PPTX
Type casting
PPTX
Algorithm and pseudo codes
PPTX
Arrays in Java
PPTX
FLOW OF CONTROL-INTRO PYTHON
PPTX
Variables in python
PPTX
Syntax Analysis in Compiler Design
PPT
Function overloading(c++)
PDF
Exception handling
PPTX
Data structures and algorithms
PPTX
DBMS - RAID
PPS
Java Exception handling
Code Optimization
15. Transactions in DBMS
python conditional statement.pptx
Python Decision Making
Python programming : Control statements
Thread priorities
Looping statement in python
Functions in Python
Type casting
Algorithm and pseudo codes
Arrays in Java
FLOW OF CONTROL-INTRO PYTHON
Variables in python
Syntax Analysis in Compiler Design
Function overloading(c++)
Exception handling
Data structures and algorithms
DBMS - RAID
Java Exception handling
Ad

Similar to control statements in python.pptx (20)

PPTX
ControlStructures.pptx5t54t54444444444444444
PPT
C statements.ppt presentation in c language
PPT
Python session3
PPTX
Control Structures Python like conditions and loops
PPTX
Selection Statements in C Programming
PPT
C++ chapter 4
PDF
Controls & Loops in C
PPTX
07 flow control
PPTX
C Programming Control Structures(if,if-else)
DOCX
iterations.docx
PDF
Control flow statements in java web applications
PPTX
Decision statements in c language
PPTX
Decision statements in c laguage
PPTX
TN 12 computer Science - ppt CHAPTER-6.pptx
PPTX
control-structure.pptxcontrol-structure.pptx
PPTX
pds first unit module 2 MODULE FOR ppt.pptx
PDF
CS305PC_C++_UNIT 2.pdf jntuh third semester
PPTX
Control Statement programming
PDF
E-Notes_3721_Content_Document_20250107032537PM.pdf
PDF
Chapter 8 - Conditional Statement
ControlStructures.pptx5t54t54444444444444444
C statements.ppt presentation in c language
Python session3
Control Structures Python like conditions and loops
Selection Statements in C Programming
C++ chapter 4
Controls & Loops in C
07 flow control
C Programming Control Structures(if,if-else)
iterations.docx
Control flow statements in java web applications
Decision statements in c language
Decision statements in c laguage
TN 12 computer Science - ppt CHAPTER-6.pptx
control-structure.pptxcontrol-structure.pptx
pds first unit module 2 MODULE FOR ppt.pptx
CS305PC_C++_UNIT 2.pdf jntuh third semester
Control Statement programming
E-Notes_3721_Content_Document_20250107032537PM.pdf
Chapter 8 - Conditional Statement
Ad

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Classroom Observation Tools for Teachers
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
master seminar digital applications in india
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
01-Introduction-to-Information-Management.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Final Presentation General Medicine 03-08-2024.pptx
TR - Agricultural Crops Production NC III.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Supply Chain Operations Speaking Notes -ICLT Program
PPH.pptx obstetrics and gynecology in nursing
Classroom Observation Tools for Teachers
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Insiders guide to clinical Medicine.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
master seminar digital applications in india
human mycosis Human fungal infections are called human mycosis..pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
01-Introduction-to-Information-Management.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Computing-Curriculum for Schools in Ghana
Final Presentation General Medicine 03-08-2024.pptx

control statements in python.pptx

  • 2. CONTROL sTATEMENTs Defination: Control statements are the statements which control or change the flow of execution.
  • 3. The following are the control statements available in python:  If statements  If….else statement  If….elif…else statement  While loop  For loop  Break statement  Continue statement  Pass statement  Assert statement  Return statement
  • 4. The if statement: This statement is used to execute one or more statement depending up on whether a condition is true or not. Syntax: if condition: statements code: num=1 output: if num==1: one print(“one”)
  • 5. The if…else statement: This statement execute the group of statements when a condition is true, otherwise it will execute the else statement. Syntax: if condition: statements else: statements code: x=int(input(“enter the value”)) if x%2==0: print(“even”) else: print(“odd”)
  • 6. The if..elif..else statement: The if..elif..else statement is used to execute the block of statements among more than two condition. Syntax: if condition1: code: num=5 statements1 if num==0: elif condition2: print(“zero value”) statement2 elif num<0: elif condition3: print(“negative”) statement3 else: else: print(“positive”) statement4
  • 7. The while loop: The while loop is useful to execute a group of statement several times repeatedly depending up on whether a condition is True or False. Syntax: while condition: statements code: x=1 while x<=10: print(“x=”,x) x+=1
  • 8. The for loop: The for loop is useful to iterate over the elements of a sequence.it means ,the for loop can be used to execute a group of statement repeatedly depending upon the number of element in the sequence syntax: for var in sequence: statements code: str=“hello” for ch in str: print(ch)
  • 9. The break statement: The break statement can be used Inside the a for loop or while loop to come out of the loop. When ‘break’ is executed, the python interpreter jumps out of the loop to process the next statement in the program. Syntax: while/for condition: statements code: x=0 while x<=10: print(“x=”,x) if x==5: break
  • 10. The continue statements: The continue statement is used within loop to skip the some part of the current iteration and move in to the next iteration. Syntax: while/for condition: if condition: continue code: x=0 while x<=10: print(“x=”,x) if x==5: continue
  • 11. The pass statement: The pass statement does not do anything. It is used with ‘if’ statement or inside the loop to represent no operation. We use pass statement when we need a statement syntactically but we do not want to do any operation. The assert statement: The assert statement is useful to check if a particular condition is fulfilled or not. Syntax: assert expression, message code: x=int(input(“enter the value greater than 0=”)) assert x>0, “wrong input entered” print(“you entered:” ,x)
  • 12. The return statement: A return statement is used to end the execution of the function call and “return” the result. Syntax: def fun() statements return expression code: def cube(x): r=x**3 return r