Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Advertisements

1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS150 Introduction to Computer Science 1
CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
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.
General Programming Introduction to Computing Science and Programming I.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Designing Programs with Branches CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
More While Loop Examples CS303E: Elements of Computers and Programming.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
CSCI-100 Introduction to Computing
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CS 100 Introduction to Computing Seminar October 7, 2015.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Iterative Structures (Loops) CS 1401 Spring 2013 Shirley Moore, Instructor February 28, 2013.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
More on Functions (Part 2)
CS 1430: Programming in C++ No time to cover HiC.
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More Nested Loops and Lab 5
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
String Encodings and Penny Math
Decision Structures, String Comparison, Nested Structures
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Types, Truth, and Expressions (Part 2)
Count Controlled Loops (Nested)
Intro to Nested Looping
Introduction to Computer Programming
Types, Truth, and Expressions (Part 2)
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
INC 161 , CPE 100 Computer Programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More on Functions (Part 2)
More on Functions (Part 2)
Intro to Nested Looping
Let’s all Repeat Together
Types, Truth, and Expressions (Part 2)
Intro to Computer Science Loops
Programming Concepts and Database
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Nested Looping
String Encodings and Penny Math
Millennium High School Agenda Calendar
REPETITION Why Repetition?
Presentation transcript:

Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg

Nesting Nesting means to place one code structure inside of another Nested if statements If (a<1): if (a==0): print(“Hey, this is zero”) else: print(“This is a negative number”) 2

Nested Loops We can also nest loops Can be very powerful, but tricky! 3

The idea of nested looping for x in range(1,4): for y in range(1,5): print (x, '*', y, '=', (x*y)) How many times will this print??

Finding Out if a Number is Prime An integer, N, is prime if it is not evenly divisible by any of the numbers from 2 to N-1

Finding Out if a Number is Prime Is 41 a prime number? Is 77 a prime number?

Finding Out if a Number is Prime Is 413 a prime number? Is 419 a prime number?

Let’s Write a Design Paragraph Inputs? Steps to calculate result Outputs? 8

Finding Out if a Number is Prime Write a program that:  Asks for an integer greater than 2  Keeps prompting until it gets one  Checks the numbers from 2 to N-1 to see if N is evenly divisible by that number  Prints a message either way.

So how would we change this… To print information about all of the numbers from 2 to 100?  Nested Looping