SlideShare a Scribd company logo
Loops in python
programming
➔ For
➔ while
Outline
1. For loop
2. Range function
3. Break, continue, and Pass
statement
4. Booleans
5. While loop
6. Nested loop
For Loop
The for loop in python iterates over the items of any sequence
be it a list or a string. Moreover, using for loop in the program
will minimize the line of code.
Points to keep in mind while using for loop in python:
➔ It should always start with for keyword and should
end with a colon(:).
➔ The statements inside the loop should be
indented(four spacebars).
Syntax:
For iterator_variable in sequence:
statement(s)
Example
Code:
for i in range(6):
print(“Hello World!”)
Output:
print(“Hello World!”)
print(“Hello World!”)
print(“Hello World!”)
print(“Hello World!”)
print(“Hello World!”)
This is actually a temporary
variable which store the
number of iteration
Number of times you want to
execute the statement
Range function
To iterate over a sequence of numbers, the built-in function
range() comes in handy. It generates arithmetic
progressions. For example, if we want to print a whole number
from 0 to 10, it can be done using a range(11) function in a for
loop.
In a range() function we can also define an optional start and
the endpoint to the sequence. The start is always included
while the endpoint is always excluded.
Example:
for i in range(1, 6):
print("Hello World!")
Output: Prints Hello World! five times
Starting point
Ending point
Range function
The range() function also takes in another optional
parameter i.e. step size. Passing step size in a range()
function is important when you want to print the value
uniformly with a certain interval.
Step size is always passed as a third parameter where the
first parameter is the starting point and the second
parameter is the ending point. And if the step_size is not
provided it will take 1 as a default step_size.
Example:
for i in range(0,20, 2):
print(i)
Output: prints all the even numbers till 20
Step size
cont….
Sum of numbers
-Write a program to find the sum of all the numbers less than
a number entered by the user. Display the sum.
Expected Output:
1
Break, Continue, & Pass Statement
(Loop control statement)
➔ A break statement is used to immediately terminate a
loop.
➔ A continue statement is used to skip out future
commands inside a loop and return to the top of the
loop.
➔ A Pass is a null operation — when it is executed,
nothing happens. It is useful as a placeholder when a
statement is required syntactically when no code
needs to be executed.
➔ These statements can be used with for or while loops.
Break, Continue, & Pass Statement (Loop control statement)
Example:
for i in range(10):
if i == 3:
break
print(i)
Output:
0
1
2
Break
for i in range(5):
if i == 3:
continue
print(i)
Output:
0
1
2
4
Continue
for i in range(10):
Pass
Output:
Nothing will be printed
Pass
Magic Number
Write a program that makes the user guess a particular
number between 1 and 100. Save the number to be
guessed in a variable called magic_number.
If the user guesses a number higher than the secret
number, you should say Too high!. Similarly, you should
say Too low! if they guess a number lower than the secret
number. Once they guess the number, say Correct!
Expected Output:
2
Boolean
A boolean is a value that can be either True or False.
Example:
brought_food = True
brought_drink = False
- Boolean variables don't have quotation marks.
- The values must start with capital letters.
While Loop
➔ while loop repeatedly carries out a target statement while the condition is
true. The loop iterates as long as the defined condition is True.
➔ When the condition becomes false, program control passes to the line
immediately following the loop.
Example:
while True:
print("I am a programmer")
break
while False:
print("Not printed because while the condition is already False")
break
Output:
I am a programmer
While Loop
Example:
x = 1
while x > 0:
print ("Hello!")
x = x - 1
print ("I like Python.")
Output:
Hello!
I like Python.
Guess the number
Write a program where the user enters a number.
If the number matches the number, acknowledge
the user and stop the program. If the number
does not match, keep asking for the next number.
Expected Output:
3
Nested Loop
Loop within a loop is called a nested loop.
➔ For loop within for loop is called a nested for loop.
➔ While loop within while loop is called as nested while
loop.
for i in range(4):
for j in range(3):
print ("Hello!")
Example: Nested for loop
i = 1
j = 5
while i < 4:
while j < 8:
print(i,",", j)
j = j + 1 j
i = i + 1
Example: Nested while loop
Nested Loop(Example)
for i in range(4):
x = 5
while x > 1:
print (x)
x = x - 1
Output:
5
4
3
2
5
4
3
2
5
4
3
2
5
4
3
2
Rolling a dice
Write a program that will print out all combinations that can
be made when 2 dice are rolled. And should continue until all
values up to 6, and 6 are printed. (Hint: You should have a
space after each comma!)
Expected Output:
4
Multiplication Table:
Write a program to print a multiplication
table to 12 of a given number.
Expected Output:
1
Printing pattern:
Write a program to print the following two
patterns implementing the nested loop
concept.
2
While_for_loop presententationin first year students

More Related Content

Similar to While_for_loop presententationin first year students

Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
iterations.docx
iterations.docxiterations.docx
iterations.docx
ssuser2e84e4
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Priyom Majumder
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
malekaanjum1
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
Mohamed Elsayed
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
SzeChingChen
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
While loop
While loopWhile loop
While loop
RabiyaZhexembayeva
 
Loops in c
Loops in cLoops in c
Loops in c
shubhampandav3
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
altwirqi
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
RajKumar Rampelli
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
Akhil Kaushik
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
AnirudhaGaikwad4
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
Helpmeinhomework
 
Python if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_StatementPython if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_Statement
AbhishekGupta692777
 
Chapter08.pptx
Chapter08.pptxChapter08.pptx
Chapter08.pptx
GiannisPagges
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
Ebad ullah Qureshi
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
Suneel Dogra
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
Hattori Sidek
 

Similar to While_for_loop presententationin first year students (20)

Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
iterations.docx
iterations.docxiterations.docx
iterations.docx
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
While loop
While loopWhile loop
While loop
 
Loops in c
Loops in cLoops in c
Loops in c
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 
Python if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_StatementPython if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_Statement
 
Chapter08.pptx
Chapter08.pptxChapter08.pptx
Chapter08.pptx
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 

Recently uploaded

AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
drshikhapandey2022
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
AI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdfAI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdf
mahaffeycheryld
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Massimo Talia
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
Seetal Daas
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Transcat
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
OKORIE1
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 

Recently uploaded (20)

AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
AI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdfAI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdf
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 

While_for_loop presententationin first year students

  • 2. Outline 1. For loop 2. Range function 3. Break, continue, and Pass statement 4. Booleans 5. While loop 6. Nested loop
  • 3. For Loop The for loop in python iterates over the items of any sequence be it a list or a string. Moreover, using for loop in the program will minimize the line of code. Points to keep in mind while using for loop in python: ➔ It should always start with for keyword and should end with a colon(:). ➔ The statements inside the loop should be indented(four spacebars). Syntax: For iterator_variable in sequence: statement(s)
  • 4. Example Code: for i in range(6): print(“Hello World!”) Output: print(“Hello World!”) print(“Hello World!”) print(“Hello World!”) print(“Hello World!”) print(“Hello World!”) This is actually a temporary variable which store the number of iteration Number of times you want to execute the statement
  • 5. Range function To iterate over a sequence of numbers, the built-in function range() comes in handy. It generates arithmetic progressions. For example, if we want to print a whole number from 0 to 10, it can be done using a range(11) function in a for loop. In a range() function we can also define an optional start and the endpoint to the sequence. The start is always included while the endpoint is always excluded. Example: for i in range(1, 6): print("Hello World!") Output: Prints Hello World! five times Starting point Ending point
  • 6. Range function The range() function also takes in another optional parameter i.e. step size. Passing step size in a range() function is important when you want to print the value uniformly with a certain interval. Step size is always passed as a third parameter where the first parameter is the starting point and the second parameter is the ending point. And if the step_size is not provided it will take 1 as a default step_size. Example: for i in range(0,20, 2): print(i) Output: prints all the even numbers till 20 Step size cont….
  • 7. Sum of numbers -Write a program to find the sum of all the numbers less than a number entered by the user. Display the sum. Expected Output: 1
  • 8. Break, Continue, & Pass Statement (Loop control statement) ➔ A break statement is used to immediately terminate a loop. ➔ A continue statement is used to skip out future commands inside a loop and return to the top of the loop. ➔ A Pass is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically when no code needs to be executed. ➔ These statements can be used with for or while loops.
  • 9. Break, Continue, & Pass Statement (Loop control statement) Example: for i in range(10): if i == 3: break print(i) Output: 0 1 2 Break for i in range(5): if i == 3: continue print(i) Output: 0 1 2 4 Continue for i in range(10): Pass Output: Nothing will be printed Pass
  • 10. Magic Number Write a program that makes the user guess a particular number between 1 and 100. Save the number to be guessed in a variable called magic_number. If the user guesses a number higher than the secret number, you should say Too high!. Similarly, you should say Too low! if they guess a number lower than the secret number. Once they guess the number, say Correct! Expected Output: 2
  • 11. Boolean A boolean is a value that can be either True or False. Example: brought_food = True brought_drink = False - Boolean variables don't have quotation marks. - The values must start with capital letters.
  • 12. While Loop ➔ while loop repeatedly carries out a target statement while the condition is true. The loop iterates as long as the defined condition is True. ➔ When the condition becomes false, program control passes to the line immediately following the loop. Example: while True: print("I am a programmer") break while False: print("Not printed because while the condition is already False") break Output: I am a programmer
  • 13. While Loop Example: x = 1 while x > 0: print ("Hello!") x = x - 1 print ("I like Python.") Output: Hello! I like Python.
  • 14. Guess the number Write a program where the user enters a number. If the number matches the number, acknowledge the user and stop the program. If the number does not match, keep asking for the next number. Expected Output: 3
  • 15. Nested Loop Loop within a loop is called a nested loop. ➔ For loop within for loop is called a nested for loop. ➔ While loop within while loop is called as nested while loop. for i in range(4): for j in range(3): print ("Hello!") Example: Nested for loop i = 1 j = 5 while i < 4: while j < 8: print(i,",", j) j = j + 1 j i = i + 1 Example: Nested while loop
  • 16. Nested Loop(Example) for i in range(4): x = 5 while x > 1: print (x) x = x - 1 Output: 5 4 3 2 5 4 3 2 5 4 3 2 5 4 3 2
  • 17. Rolling a dice Write a program that will print out all combinations that can be made when 2 dice are rolled. And should continue until all values up to 6, and 6 are printed. (Hint: You should have a space after each comma!) Expected Output: 4
  • 18. Multiplication Table: Write a program to print a multiplication table to 12 of a given number. Expected Output: 1
  • 19. Printing pattern: Write a program to print the following two patterns implementing the nested loop concept. 2