SlideShare a Scribd company logo
1 of 8
Download to read offline
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

More Related Content

Similar to While Loop in python engineering .pdf

Similar to 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++
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
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
 

Recently uploaded

Degrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptxDegrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptx
Mostafa Mahmoud
 
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
AshwaniAnuragi1
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 

Recently uploaded (20)

Degrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptxDegrees of freedom for the robots 1.pptx
Degrees of freedom for the robots 1.pptx
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 
Danikor Product Catalog- Screw Feeder.pdf
Danikor Product Catalog- Screw Feeder.pdfDanikor Product Catalog- Screw Feeder.pdf
Danikor Product Catalog- Screw Feeder.pdf
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
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...
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and Clipping
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Overview of Transformation in Computer Graphics
Overview of Transformation in Computer GraphicsOverview of Transformation in Computer Graphics
Overview of Transformation in Computer Graphics
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 

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