0% found this document useful (0 votes)
539 views

Control Statements Python

This document defines and explains the different types of control statements in Python including if, if-else, if-elif-else statements, while and for loops, and the break and continue statements. It provides the structure and purpose of each statement: if statements execute code conditionally, if-else adds alternative code, if-elif-else checks multiple conditions, while loops repeat until a condition is false, for loops iterate over sequences, break exits loops, and continue skips to the next iteration. Control statements manage program flow by making decisions or repeating code blocks.

Uploaded by

Sayan Sarkar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
539 views

Control Statements Python

This document defines and explains the different types of control statements in Python including if, if-else, if-elif-else statements, while and for loops, and the break and continue statements. It provides the structure and purpose of each statement: if statements execute code conditionally, if-else adds alternative code, if-elif-else checks multiple conditions, while loops repeat until a condition is false, for loops iterate over sequences, break exits loops, and continue skips to the next iteration. Control statements manage program flow by making decisions or repeating code blocks.

Uploaded by

Sayan Sarkar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Control

statements
in Python
SAYAN SARKA R
BWU/BTA /2 2 /1 9 7
COURSE CO DE – ESCM- 3 0 3
SEM- 3 R D
Contents
1. Definition
2. Types
3. If statement
4. If-else statement
5. If-elif-else statement
6. While loop
7. For loop
8. Break statement
9. Continue statement
What is control statement?
In Python, control statements are used to manage the flow of a program by making decisions or
repeating certain blocks of code.
 Types:

o If statement o For loop

o If-else statement o Break statement


o If-elif-else statement
o Continue statement
o While loop
 If statement:
o The 'if' statement is used for conditional execution. It allows you to execute a block of code
only if a specified condition is true.

o Structure of code:
if condition:
# code to execute if the condition is true

 If-else statement:
o The 'if-else' statement extends the if statement by providing an alternative block of code to
execute when the condition is false.

o Structure of code:
if condition:
# code to execute if the condition is true
else:
# code to execute if the condition is false
 If-elif-else statement:
o The 'if-elif-else' statement allows you to check multiple conditions and execute different
blocks of code based on the first true condition.

o Structure of code:
if condition1:
# code to execute if condition1 is true
elif condition2:
# code to execute if condition2 is true
else:
# code to execute if none of the conditions are true
 While loop;
o The 'while' loop is used for repeated execution of a block of code as long as a specified
condition is true.

o Structure of code:
while condition:
# code to execute while the condition is true
 For loop:
o The ‘for’ loop is used for iterating over a sequence (such as a list, tuple, or string) or other
iterable objects.

o Structure of code:
for variable in iterable:
# code to execute for each element in the iterable

 Break statement:
o The 'break' statement is used to exit a loop prematurely, regardless of whether the loop
condition is true or false.

o Structure of code:
while condition:
# code
if some_condition:
break
# more code
 Continue statement:
o The 'continue' statement is used to skip the rest of the code inside a loop for the current
iteration and continue with the next iteration.

o Structure of code:
for variable in iterable:
if some_condition:
continue
# code to execute for each element in the iterable
Reference
1. Let us Python(4th Edition)- Yashavant Kenetkar
2. Geeks for geeks (https://www.geeksforgeeks.org/)
3. Google Bard (https://bard.google.com/?hl=en-GB)
Thank You

You might also like