SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
NAME:- MITESH NITIN CHAUDHARI
PRN:- 202301040106
DIV:- C2
ROLL NO. - C205
Essentials of Data Science
While
Loop
Python
01
Python supports to have an else statement associated with a loop
statement
If else statement is used with a while loop, the else statement is
executed when the condition becomes false
Using else statement with a while loop
while condition:
# Code to be executed when the condition is True
else:
# Code to be executed when the condition becomes False
Syntax
Introduction to while loop
A while loop allows general repetition based upon the repeated
testing of a Boolean condition
Where, loop body contain the single statement or set of statements
(compound statement) or an empty statement.
A while loop is used to execute a set of statements as long as
condition is true
A loop statement allows us to execute a statement multiple times
Syntax How the While Loop
Works
1 Initialization
Set the initial state of the loop
variables.
2 Condition Check
Evaluate the condition expression to
determine if the loop should
continue.
3 Code Execution
Execute the code block within the
loop.
while(condition):
#code
#Initialization
09
WHILE LOOP
Working of While loop
05
Examples
i = 0 # Initialize a variable
while i < 5: # While the variable is
print(i) less than 5
i+=1 print the variable and
increment it by 1
# The loop will stop when i is equal to 5
# Initialize a list
nums = [1, 2, 3, 4, 5]
# Iterate over the list and print each element
i = 0
while i < len(nums):
print(nums[i])
i += 1
# The loop will stop when i is equal to the length of the list
THANK YOU

Contenu connexe

Similaire à While Loop in python engineering .pdf

Similaire à While Loop in python engineering .pdf (20)

Loops In C++
Loops In C++Loops In C++
Loops In C++
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 
Decision making and loop in C#
Decision making and loop in C#Decision making and loop in C#
Decision making and loop in C#
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
Loops
LoopsLoops
Loops
 
Deeksha gopaliya
Deeksha gopaliyaDeeksha gopaliya
Deeksha gopaliya
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
Loops c++
Loops c++Loops c++
Loops c++
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 
Control statements
Control statementsControl statements
Control statements
 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docx
 
2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
 
Loops
LoopsLoops
Loops
 

Dernier

Microkernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemMicrokernel in Operating System | Operating System
Microkernel in Operating System | Operating System
Sampad Kar
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
drjose256
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
Madan Karki
 

Dernier (20)

Microkernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemMicrokernel in Operating System | Operating System
Microkernel in Operating System | Operating System
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor bank
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..pdf
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
AI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdfAI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdf
 
Supermarket billing system project report..pdf
Supermarket billing system project report..pdfSupermarket billing system project report..pdf
Supermarket billing system project report..pdf
 
Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...
Vip ℂall Girls Karkardooma Phone No 9999965857 High Profile ℂall Girl Delhi N...
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
 

While Loop in python engineering .pdf

  • 1. NAME:- MITESH NITIN CHAUDHARI PRN:- 202301040106 DIV:- C2 ROLL NO. - C205 Essentials of Data Science
  • 3. Python supports to have an else statement associated with a loop statement If else statement is used with a while loop, the else statement is executed when the condition becomes false Using else statement with a while loop while condition: # Code to be executed when the condition is True else: # Code to be executed when the condition becomes False Syntax
  • 4. Introduction to while loop A while loop allows general repetition based upon the repeated testing of a Boolean condition Where, loop body contain the single statement or set of statements (compound statement) or an empty statement. A while loop is used to execute a set of statements as long as condition is true A loop statement allows us to execute a statement multiple times
  • 5. Syntax How the While Loop Works 1 Initialization Set the initial state of the loop variables. 2 Condition Check Evaluate the condition expression to determine if the loop should continue. 3 Code Execution Execute the code block within the loop. while(condition): #code #Initialization
  • 7. 05 Examples i = 0 # Initialize a variable while i < 5: # While the variable is print(i) less than 5 i+=1 print the variable and increment it by 1 # The loop will stop when i is equal to 5 # Initialize a list nums = [1, 2, 3, 4, 5] # Iterate over the list and print each element i = 0 while i < len(nums): print(nums[i]) i += 1 # The loop will stop when i is equal to the length of the list