SlideShare a Scribd company logo
Process Control-Loops
VKS-12
LOOPS
Iteration
VKS-12
VKS-12
 Repeated execution of a set of statements is called iteration
 Iteration is achieved in programing language using loop.
 The iteration can be definite or indefinite depending upon
the user logic
 All programming language provides some construct which are
used to automatically repeat a set of statements generally
called Loops
 Python provide two type of loops while and for
 while is condition-controlled loop
 for is count-control loop
For loops are traditionally used when you have a piece of code which
you want to repeat n number of times.
While Loop is used when a condition is to be met, or if you want a
piece of code to repeat forever,
VKS-12
Generally any loop in Python has three (3) components:
a) Control Variable and its Initialisation: Generally a loop in Python
has a control variable. Control variable is generally an integer type or
character type or floating point type. But we can have loop in Python
with out a control variable. We will discuss such loops later. If a loop
has a control variable then the control variable has to be initialized.
b) Terminating Condition: Generally a loop should terminate after
certain number of iterations. Terminating condition of the loop in
Python is a condition (logical expression) involving the Control
Variable. Condition or logical expression plays a very important in the
working of a loop in Python since number of times loop is repeated
depends on the condition.
c) Updation of Control Variable: Every Python loop repeats statement
or block. Inside the block or statement of a loop, control variable is
updated (value of the control variable is either incremented or
decremented), so that the loop terminates after certain number of
iterations.
VKS-12
Loop through a set of statements as long as a condition is true
Syntax
while(Condition) :
Python Statement(s)
Updating of control variable
The (condition) may be any Python valid logical expression.
When program execution reaches a while statement, the following events occur:
1. The (condition) is evaluated.
2. Condition is TRUE (nonzero), the Block / Statement is executed.
3. Inside the Block / Statement, control variable is updated and Condition is tested
once
These three steps are repeated till Condition is FALSE.
When the condition is evaluated to be false, the loop is terminates.
VKS-12
k<=5 print(k) k+=1
TRUE 1 2
TRUE 2 3
TRUE 3 4
TRUE 4 5
FALSE Loop terminated
TRUE 5 6
VKS-12
K<=20 print(k) K+=2
True 2 4
True 4 6
VKS-12
range()
Function range() generates a list of numbers, which
is generally used to iterate over with for loop. Often
you will want to use this when you want to perform
an action for fixed number of times.
Function range() has three syntaxes.
VKS-12
1. range(StopVal) generates sequence of
integers 0, 1, 2, 3, …, StopVal-1
Start value of the sequence is always 0 (zero)
when range() function has single parameter.
range(6) will generate sequence of integers
0, 1, 2, 3, 4, 5
range(11) will generate integers
0, 1, 2, 3, …, 9, 10
range(0) or range(-5) does not generate an any
sequence because 0>StopVal
VKS-12
2. range(StartVal, StopVal) generates integers
StartVal, StartVal +1, StartVal +2, , …, StopVal-1
range(1, 6) will generate sequence of integers
1, 2, 3, 4, 5
range(6, 11) will generate sequence of integers
6, 7, 8, 9, 10
range(-3, 4) will generate sequence of integers
-3, -2, -1, 0, 1, 2, 3
range(3, 0) or range(3, -4) does not generate an any
sequence of integer because StartVal>StopVal
VKS-12
3. range(StartVal, StopVal, Step)
a) Generates integers StartVal, StartVal + Step,
StartVal + 2*Step, …, StopVal-1
When StartVal<StopVal and Step>0
Generates a sequence in ascending order.
b) Generates integers StartVal, StartVal - Step,
StartVal - 2*Step, …, StopVal+1
When StartVal>StopVal and Step<0
VKS-12
Generates a sequence in descending order.
range(1, 6, 1) will generate sequence of integers 1, 2, 3, 4, 5
range(2, 12, 2) will generate sequence of integers 2, 4, 6, 8, 10
range(1, 12, 2) will also generate sequence of integers 1, 3, 5, 7, 9, 11
range(-1, -6, -1) will generate sequence of integers -1, -2, -3, -4, -5
range(15, 2, 3) will generate sequence of integers 15, 12, 9, 6, 3
range(-15, -2, 3) will generate sequence of integers -15, -12, -9, -6, -3
range(-5, 6, 2) will generate sequence of integers -5, -3, -1, 1, 3, 5
range(-9, 0, -2) does not generate an any sequence because
StartVal<StopVal and Step is -2
Ad

More Related Content

Similar to Introduction to Python loops while and for .pptx (20)

Control structures
Control structuresControl structures
Control structures
M Vishnuvardhan Reddy
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
Sriman Sawarthia
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Thomas Graf
 
Chap05
Chap05Chap05
Chap05
Terry Yoast
 
control-statements, control-statements, control statement
control-statements, control-statements, control statementcontrol-statements, control-statements, control statement
control-statements, control-statements, control statement
crrpavankumar
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
Rai University
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
Rai University
 
Managing input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and loopingManaging input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and looping
letheyabala
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
Rai University
 
Linear control system Open loop & Close loop Systems
Linear control system Open loop & Close loop SystemsLinear control system Open loop & Close loop Systems
Linear control system Open loop & Close loop Systems
SohaibUllah5
 
Control structures
Control structuresControl structures
Control structures
Isha Aggarwal
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
SHRIRANG PINJARKAR
 
Bsc cs pic u-3 handling input output and control statements
Bsc cs  pic u-3 handling input output and control statementsBsc cs  pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
Rai University
 
Design and Simulation of Aircraft Autopilot to Control the Pitch Angle
Design and Simulation of Aircraft Autopilot to Control the Pitch AngleDesign and Simulation of Aircraft Autopilot to Control the Pitch Angle
Design and Simulation of Aircraft Autopilot to Control the Pitch Angle
Ehab Al hamayel
 
stop and wait _
stop and wait                            _stop and wait                            _
stop and wait _
SwatiHans10
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JanCarlBriones2
 
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Thomas Graf
 
control-statements, control-statements, control statement
control-statements, control-statements, control statementcontrol-statements, control-statements, control statement
control-statements, control-statements, control statement
crrpavankumar
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
Rai University
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
Rai University
 
Managing input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and loopingManaging input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and looping
letheyabala
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
Rai University
 
Linear control system Open loop & Close loop Systems
Linear control system Open loop & Close loop SystemsLinear control system Open loop & Close loop Systems
Linear control system Open loop & Close loop Systems
SohaibUllah5
 
Bsc cs pic u-3 handling input output and control statements
Bsc cs  pic u-3 handling input output and control statementsBsc cs  pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
Rai University
 
Design and Simulation of Aircraft Autopilot to Control the Pitch Angle
Design and Simulation of Aircraft Autopilot to Control the Pitch AngleDesign and Simulation of Aircraft Autopilot to Control the Pitch Angle
Design and Simulation of Aircraft Autopilot to Control the Pitch Angle
Ehab Al hamayel
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JanCarlBriones2
 

More from Vinod Srivastava (9)

Understanding Queue in Python using list 2019.pptx
Understanding Queue in Python using list 2019.pptxUnderstanding Queue in Python using list 2019.pptx
Understanding Queue in Python using list 2019.pptx
Vinod Srivastava
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
Python Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-FinallyPython Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-Finally
Vinod Srivastava
 
Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
Vinod Srivastava
 
python-strings.pptx
python-strings.pptxpython-strings.pptx
python-strings.pptx
Vinod Srivastava
 
Vks python
Vks pythonVks python
Vks python
Vinod Srivastava
 
User documentationinter
User documentationinterUser documentationinter
User documentationinter
Vinod Srivastava
 
Graphics sw
Graphics swGraphics sw
Graphics sw
Vinod Srivastava
 
Understanding Queue in Python using list 2019.pptx
Understanding Queue in Python using list 2019.pptxUnderstanding Queue in Python using list 2019.pptx
Understanding Queue in Python using list 2019.pptx
Vinod Srivastava
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
Python Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-FinallyPython Exception handling using Try-Except-Finally
Python Exception handling using Try-Except-Finally
Vinod Srivastava
 
Ad

Recently uploaded (20)

2024 Digital Equity Accelerator Report.pdf
2024 Digital Equity Accelerator Report.pdf2024 Digital Equity Accelerator Report.pdf
2024 Digital Equity Accelerator Report.pdf
dominikamizerska1
 
Process Mining at Deutsche Bank - Journey
Process Mining at Deutsche Bank - JourneyProcess Mining at Deutsche Bank - Journey
Process Mining at Deutsche Bank - Journey
Process mining Evangelist
 
50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd
emir73065
 
Automation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success storyAutomation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success story
Process mining Evangelist
 
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
muhammed84essa
 
CS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docxCS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docx
nidarizvitit
 
Publication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdf
Publication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdfPublication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdf
Publication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdf
StatsCommunications
 
AI ------------------------------ W1L2.pptx
AI ------------------------------ W1L2.pptxAI ------------------------------ W1L2.pptx
AI ------------------------------ W1L2.pptx
AyeshaJalil6
 
Multi-tenant Data Pipeline Orchestration
Multi-tenant Data Pipeline OrchestrationMulti-tenant Data Pipeline Orchestration
Multi-tenant Data Pipeline Orchestration
Romi Kuntsman
 
Transforming health care with ai powered
Transforming health care with ai poweredTransforming health care with ai powered
Transforming health care with ai powered
gowthamarvj
 
HershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistributionHershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistribution
hershtara1
 
TOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdf
TOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdfTOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdf
TOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdf
NhiV747372
 
文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询
文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询
文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询
Taqyea
 
Dr. Robert Krug - Expert In Artificial Intelligence
Dr. Robert Krug - Expert In Artificial IntelligenceDr. Robert Krug - Expert In Artificial Intelligence
Dr. Robert Krug - Expert In Artificial Intelligence
Dr. Robert Krug
 
Introduction to systems thinking tools_Eng.pdf
Introduction to systems thinking tools_Eng.pdfIntroduction to systems thinking tools_Eng.pdf
Introduction to systems thinking tools_Eng.pdf
AbdurahmanAbd
 
Lesson 6-Interviewing in SHRM_updated.pdf
Lesson 6-Interviewing in SHRM_updated.pdfLesson 6-Interviewing in SHRM_updated.pdf
Lesson 6-Interviewing in SHRM_updated.pdf
hemelali11
 
Automated Melanoma Detection via Image Processing.pptx
Automated Melanoma Detection via Image Processing.pptxAutomated Melanoma Detection via Image Processing.pptx
Automated Melanoma Detection via Image Processing.pptx
handrymaharjan23
 
RAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit FrameworkRAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit Framework
apanneer
 
Language Learning App Data Research by Globibo [2025]
Language Learning App Data Research by Globibo [2025]Language Learning App Data Research by Globibo [2025]
Language Learning App Data Research by Globibo [2025]
globibo
 
Fundamentals of Data Analysis, its types, tools, algorithms
Fundamentals of Data Analysis, its types, tools, algorithmsFundamentals of Data Analysis, its types, tools, algorithms
Fundamentals of Data Analysis, its types, tools, algorithms
priyaiyerkbcsc
 
2024 Digital Equity Accelerator Report.pdf
2024 Digital Equity Accelerator Report.pdf2024 Digital Equity Accelerator Report.pdf
2024 Digital Equity Accelerator Report.pdf
dominikamizerska1
 
50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd50_questions_full.pptxdddddddddddddddddd
50_questions_full.pptxdddddddddddddddddd
emir73065
 
Automation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success storyAutomation Platforms and Process Mining - success story
Automation Platforms and Process Mining - success story
Process mining Evangelist
 
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
CERTIFIED BUSINESS ANALYSIS PROFESSIONAL™
muhammed84essa
 
CS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docxCS-404 COA COURSE FILE JAN JUN 2025.docx
CS-404 COA COURSE FILE JAN JUN 2025.docx
nidarizvitit
 
Publication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdf
Publication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdfPublication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdf
Publication-launch-How-is-Life-for-Children-in-the-Digital-Age-15-May-2025.pdf
StatsCommunications
 
AI ------------------------------ W1L2.pptx
AI ------------------------------ W1L2.pptxAI ------------------------------ W1L2.pptx
AI ------------------------------ W1L2.pptx
AyeshaJalil6
 
Multi-tenant Data Pipeline Orchestration
Multi-tenant Data Pipeline OrchestrationMulti-tenant Data Pipeline Orchestration
Multi-tenant Data Pipeline Orchestration
Romi Kuntsman
 
Transforming health care with ai powered
Transforming health care with ai poweredTransforming health care with ai powered
Transforming health care with ai powered
gowthamarvj
 
HershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistributionHershAggregator (2).pdf musicretaildistribution
HershAggregator (2).pdf musicretaildistribution
hershtara1
 
TOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdf
TOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdfTOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdf
TOAE201-Slides-Chapter 4. Sample theoretical basis (1).pdf
NhiV747372
 
文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询
文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询
文凭证书美国SDSU文凭圣地亚哥州立大学学生证学历认证查询
Taqyea
 
Dr. Robert Krug - Expert In Artificial Intelligence
Dr. Robert Krug - Expert In Artificial IntelligenceDr. Robert Krug - Expert In Artificial Intelligence
Dr. Robert Krug - Expert In Artificial Intelligence
Dr. Robert Krug
 
Introduction to systems thinking tools_Eng.pdf
Introduction to systems thinking tools_Eng.pdfIntroduction to systems thinking tools_Eng.pdf
Introduction to systems thinking tools_Eng.pdf
AbdurahmanAbd
 
Lesson 6-Interviewing in SHRM_updated.pdf
Lesson 6-Interviewing in SHRM_updated.pdfLesson 6-Interviewing in SHRM_updated.pdf
Lesson 6-Interviewing in SHRM_updated.pdf
hemelali11
 
Automated Melanoma Detection via Image Processing.pptx
Automated Melanoma Detection via Image Processing.pptxAutomated Melanoma Detection via Image Processing.pptx
Automated Melanoma Detection via Image Processing.pptx
handrymaharjan23
 
RAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit FrameworkRAG Chatbot using AWS Bedrock and Streamlit Framework
RAG Chatbot using AWS Bedrock and Streamlit Framework
apanneer
 
Language Learning App Data Research by Globibo [2025]
Language Learning App Data Research by Globibo [2025]Language Learning App Data Research by Globibo [2025]
Language Learning App Data Research by Globibo [2025]
globibo
 
Fundamentals of Data Analysis, its types, tools, algorithms
Fundamentals of Data Analysis, its types, tools, algorithmsFundamentals of Data Analysis, its types, tools, algorithms
Fundamentals of Data Analysis, its types, tools, algorithms
priyaiyerkbcsc
 
Ad

Introduction to Python loops while and for .pptx

  • 4. VKS-12  Repeated execution of a set of statements is called iteration  Iteration is achieved in programing language using loop.  The iteration can be definite or indefinite depending upon the user logic  All programming language provides some construct which are used to automatically repeat a set of statements generally called Loops  Python provide two type of loops while and for  while is condition-controlled loop  for is count-control loop For loops are traditionally used when you have a piece of code which you want to repeat n number of times. While Loop is used when a condition is to be met, or if you want a piece of code to repeat forever,
  • 5. VKS-12 Generally any loop in Python has three (3) components: a) Control Variable and its Initialisation: Generally a loop in Python has a control variable. Control variable is generally an integer type or character type or floating point type. But we can have loop in Python with out a control variable. We will discuss such loops later. If a loop has a control variable then the control variable has to be initialized. b) Terminating Condition: Generally a loop should terminate after certain number of iterations. Terminating condition of the loop in Python is a condition (logical expression) involving the Control Variable. Condition or logical expression plays a very important in the working of a loop in Python since number of times loop is repeated depends on the condition. c) Updation of Control Variable: Every Python loop repeats statement or block. Inside the block or statement of a loop, control variable is updated (value of the control variable is either incremented or decremented), so that the loop terminates after certain number of iterations.
  • 6. VKS-12 Loop through a set of statements as long as a condition is true Syntax while(Condition) : Python Statement(s) Updating of control variable The (condition) may be any Python valid logical expression. When program execution reaches a while statement, the following events occur: 1. The (condition) is evaluated. 2. Condition is TRUE (nonzero), the Block / Statement is executed. 3. Inside the Block / Statement, control variable is updated and Condition is tested once These three steps are repeated till Condition is FALSE. When the condition is evaluated to be false, the loop is terminates.
  • 7. VKS-12 k<=5 print(k) k+=1 TRUE 1 2 TRUE 2 3 TRUE 3 4 TRUE 4 5 FALSE Loop terminated TRUE 5 6
  • 9. VKS-12 range() Function range() generates a list of numbers, which is generally used to iterate over with for loop. Often you will want to use this when you want to perform an action for fixed number of times. Function range() has three syntaxes.
  • 10. VKS-12 1. range(StopVal) generates sequence of integers 0, 1, 2, 3, …, StopVal-1 Start value of the sequence is always 0 (zero) when range() function has single parameter. range(6) will generate sequence of integers 0, 1, 2, 3, 4, 5 range(11) will generate integers 0, 1, 2, 3, …, 9, 10 range(0) or range(-5) does not generate an any sequence because 0>StopVal
  • 11. VKS-12 2. range(StartVal, StopVal) generates integers StartVal, StartVal +1, StartVal +2, , …, StopVal-1 range(1, 6) will generate sequence of integers 1, 2, 3, 4, 5 range(6, 11) will generate sequence of integers 6, 7, 8, 9, 10 range(-3, 4) will generate sequence of integers -3, -2, -1, 0, 1, 2, 3 range(3, 0) or range(3, -4) does not generate an any sequence of integer because StartVal>StopVal
  • 12. VKS-12 3. range(StartVal, StopVal, Step) a) Generates integers StartVal, StartVal + Step, StartVal + 2*Step, …, StopVal-1 When StartVal<StopVal and Step>0 Generates a sequence in ascending order. b) Generates integers StartVal, StartVal - Step, StartVal - 2*Step, …, StopVal+1 When StartVal>StopVal and Step<0
  • 13. VKS-12 Generates a sequence in descending order. range(1, 6, 1) will generate sequence of integers 1, 2, 3, 4, 5 range(2, 12, 2) will generate sequence of integers 2, 4, 6, 8, 10 range(1, 12, 2) will also generate sequence of integers 1, 3, 5, 7, 9, 11 range(-1, -6, -1) will generate sequence of integers -1, -2, -3, -4, -5 range(15, 2, 3) will generate sequence of integers 15, 12, 9, 6, 3 range(-15, -2, 3) will generate sequence of integers -15, -12, -9, -6, -3 range(-5, 6, 2) will generate sequence of integers -5, -3, -1, 1, 3, 5 range(-9, 0, -2) does not generate an any sequence because StartVal<StopVal and Step is -2
  翻译: