SlideShare una empresa de Scribd logo
1 de 8
Descargar para leer sin conexión
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

Más contenido relacionado

Similar a While Loop in python engineering .pdf

Similar a 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
 

Último

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
 

Último (20)

5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
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...
 
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
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
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
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
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
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
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...
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsx
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
 
BORESCOPE INSPECTION for engins CFM56.pdf
BORESCOPE INSPECTION for engins CFM56.pdfBORESCOPE INSPECTION for engins CFM56.pdf
BORESCOPE INSPECTION for engins CFM56.pdf
 
Multivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxMultivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptx
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..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
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 

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