Intro to Nested Looping

Slides:



Advertisements
Similar presentations
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Advertisements

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.
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.
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.
More While Loop Examples CS303E: Elements of Computers and Programming.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CS 100 Introduction to Computing Seminar October 7, 2015.
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.
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.
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.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Decision making If.. else statement.
Introduction to Computing Science and Programming I
More on Functions (Part 2)
CS 1430: Programming in C++ No time to cover HiC.
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 4: Control Structures
Chapter 6: Conditional Statements and Loops
Computer Science 101 While Statement.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Introduction to Strings
More Nested Loops and Lab 5
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
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
The while Looping Structure
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)
Lists – Indexing and Sorting
CS150 Introduction to Computer Science 1
Types, Truth, and Expressions (Part 2)
Introduction to Strings
More Repetition While and For loop variations
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
Introduction to Strings
Intro to Nested Looping
String Encodings and Penny Math
Millennium High School Agenda Calendar
Introduction to Strings
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”)

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

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?

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