Presentation is loading. Please wait.

Presentation is loading. Please wait.

Count Controlled Loops (Nested)

Similar presentations


Presentation on theme: "Count Controlled Loops (Nested)"— Presentation transcript:

1 Count Controlled Loops (Nested)
Ain’t no sunshine when she’s gone …

2 Practice – Divisibility
Write a program that asks the user for an integer Then print out all numbers that are divisible by that number from 1 to 1,000

3 Practice – Divisibility (extension)
Extend your divisibility program to check for all integers from 1 to 10,000 that are divisible by two different integers simultaneously

4 Practice – Divisibility (extension)
Now, try to format your program to print out 10 numbers per line

5 Nested Loops A nested loop can be described as “a loop inside of a loop” It’s the same idea as the nested “if” statements

6 Nested Loops The inner loop of a nested loop will run through all of it’s iterations during each iteration of the outer loop In other words, during one iteration of the outside loop, the inner loop will run it’s entire course (all iterations of the inner loop) In order to find out the number of total iterations, multiply the number of iterations of all the loops

7 Practice - Times Table Write a program that prints out the times table for the number 5 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 10 = 50

8 Practice – It’s Time! Write a program that prints out every single possible time value for the day, down to the second following the military format. Output: 00:00:00 00:00:01 00:00:02 23:59:59 Note: You want to import time here just so everything doesn’t just print out all at once.

9 Practice – It’s Time! Now, let’s convert it to the clock we’re used to seeing, including am and pm. Output: 12:00:00 am 12:00:01 am 12:00:02 am 11:59:59 pm

10 Practice – Drawing Write a program that outputs this image by using nested loops # # # # # # # # # # #

11 Practice – Pascal’s Triangle?
Write a program that reproduces this triangle of numbers by the use of nested loops 1 1 2 1 2 3

12 Practice - Times Table (Extended)
Write a program that prints out the times table for a range of numbers (user input) Range of numbers for times table (low): 2 High end of range: 4 2 x 1 = x 1 = x 1 = 4 2 x 2 = x 2 = x 2 = 8 2 x 3 = x 3 = x 3 = 12 2 x 10 = x 10 = x 10 = 40


Download ppt "Count Controlled Loops (Nested)"

Similar presentations


Ads by Google