Week 5 - Friday.  What did we talk about last time?  Repetition  while loops.

Slides:



Advertisements
Similar presentations
Summer 2012 Instructor: Hassan Khosravi
Advertisements

Neal Stublen Loop Structure  Sometimes it’s useful to repeat yourself  The same actions need to occur more than once  Ensures.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Repetition. Examples When is repetition necessary/useful?
Complexity (Running Time)
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop.
Copyright © Texas Education Agency, Computer Programming For Loops.
Chapter 4: Looping CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
A revision guide for programming with python. 1.A program is a set of instructions that tells a computer what to do. 2.The role of a programmer is to.
Chapter 6 – Repetition Statements : Objectives After you have read and studied this chapter, you should be able to Implement repetition control in a program.
September 18, 2012 Analyzing Graphs of Functions Warm-up: Talk to your group about the Distance Formula worksheet given last week. Make sure you understand.
Copyright 2009 by Pearson Education Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos: Ch.
Control Structures FOR Statement Looping.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
Chapter 5 Repetition or loop structure. What is repetition or loop? repeat the execution of one or a group (block; instruction enclosed in a pair of braces)
Week 4 - Wednesday.  What did we talk about last time?  if statements  else statements  Nested selection statements.
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.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Previously Repetition Structures While, Do-While, For.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
COP 3275 – Iteration and loops Instructor: Diego Rivera-Gutierrez.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson All rights reserved.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Week 6 - Monday.  What did we talk about last time?  while loop examples  Lab 5.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Hello! Miss Davies.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Repetition Structures The long awaited …. Repetition Structures I repeat …
Testing Programs with Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python - Iteration A FOR loop is ideal if we know how many times we want to repeat. Try this code: for loopCounter in range(10): print(loopCounter) There.
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
More about Iteration Victor Norman CS104. Reading Quiz.
Week of 12/12/16 Test Review.
CS161 Introduction to Computer Science
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Chapter 5: Repetition Structures
Python - Iteration Iteration
Topics discussed in this section:
Topics Introduction to Repetition Structures
Chapter 5 Repetition.
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
Repetition Statements
Alice in Action with Java
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Chapter 8 The Loops By: Mr. Baha Hanene.
Count Controlled Loops (Nested)
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Intro to Nested Looping
Chapter (3) - Looping Questions.
Chapter 4 Loops While loop The for loop do… while break and continue
Repetition Control Structure
Intro to Nested Looping
Computer Science G10 T \2017 T shaikhah AlZeyoudi
Print the following triangle, using nested loops
Iteration – While Loops
The return Statement © 2018 Kris Jordan.
Control Structures.
Week 5 - Friday CS 121.
Presentation transcript:

Week 5 - Friday

 What did we talk about last time?  Repetition  while loops

while( condition ) { statement1; statement2; … statementn; } A whole bunch of statements

 Let’s say that you wanted to write a program to guess a number that a person had come up with  The number is between 1 and 100  Every time the computer guesses a number, the person enters:  H if the number is too high  L if the number is too low  F if the number was found

1. Start with the minimum and maximum of the range 2. Find the midpoint 3. Ask the user if the midpoint is correct 4. If the answer is too high, go to Step 1 using the minimum and the midpoint - 1 as the new range 5. If the answer is too low, go to Step 1 using the midpoint + 1 and the maximum as the new range 6. If the midpoint is correct, you’re done!

 Just as with if -statements, it’s possible to nest loops  A repetitive task can be done inside of another repetitive task  Be careful! You can make the computer do a lot of work

 Triangular numbers are 1, 3, 6, 10, …  1 = 1  3 =  6 =   Let’s write a program that expresses the n th triangular number by printing 1 on the first line, 1 and 2 on the second line, 1, 2, and 3 on the third line, and so on

 for loops  More loop examples

 Keep reading Chapter 5  Keep working on Project 2