Count Controlled Loops (Nested)

Slides:



Advertisements
Similar presentations
Nested Loops. Nested loops Just as a selection structure can be nested within another selection structure (or within a loop), a loop can also be nested.
Advertisements

Chapter 4. Loops and Character Manipulation Loops in FORTRAN are constructs that permits us to execute a sequence of statements more than once. Type of.
Computer Science 1620 Loops.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Nested Loops. Nesting Control Structures One if statement inside another one An if statement inside a loop A loop inside an if statement Control structures.
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
27/05/ Iteration Loops Nested Loops & The Step Parameter.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Nested for loops.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
I can show multiplying polynomials with the FOIL.
Objective - To multiply polynomials.
Lesson #5 Repetition and Loops.
Chapter 8: More on the Repetition Structure
Whatcha doin'? Aims: To start using Python. To understand loops.
Lesson #5 Repetition and Loops.
Topics Introduction to Repetition Structures
While Loops (Iteration 2)
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Repetition and Loop Statements
Efficiency (Chapter 2).
Control Structure Senior Lecturer
Selection CIS 40 – Introduction to Programming in Python
Lesson #5 Repetition and Loops.
Introduction to pseudocode
Intro to Nested Looping
Programming In Lesson 3.
COMP 110 Loops, loops, loops, loops, loops, loops…
Intro to Nested Looping
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
For Loops.
Multiplying by FOIL When having to multiply two binomials together, we need to have a method in place to properly multiply the terms together. This method.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Nested Loops & The Step Parameter
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Intro to Nested Looping
Week 6 CPS125.
Python programming exercise
Objectives You should be able to describe: The while Statement
Python Basics with Jupyter Notebook
Programming Control Structures
Building Java Programs
Lesson #5 Repetition and Loops.
Intro to Nested Looping
Print the following triangle, using nested loops
Building Java Programs
Integer Practice: Division
Chapter 4: Loops and Files
EE 194/Bio 196: Modeling biological systems
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

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

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

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

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

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

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

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

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.

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

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

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 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6

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 = 2 3 x 1 = 3 4 x 1 = 4 2 x 2 = 4 3 x 2 = 6 4 x 2 = 8 2 x 3 = 6 3 x 3 = 9 4 x 3 = 12 … 2 x 10 = 20 3 x 10 = 30 4 x 10 = 40