More Loops.

Slides:



Advertisements
Similar presentations
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Advertisements

1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
Rules of Integers. Positive numbers are numbers that are above zero. Negative numbers are numbers below zero.
Multiplying and Dividing Decimals by 10, 100, and 1,000
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Notes and Practice Adding and Subtracting Integers.
Adding & Subtracting INTEGERS Lesson 1-5 & 1-6. Adding & Subtracting INTEGERS ADDING INTEGERS Same sign, add & Keep! Different sign, subtract… BUT take.
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.
Count and add list of numbers From user input and from file.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
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.
Computer Science 101 For Statement. For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed.
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.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Subtracting Integers Objective: Learn to subtract integers.
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Repetition Structures
REPETITION CONTROL STRUCTURE
Chapter 5: Control Structures II (Repetition)
Chapter 5: Control Structure
CS 108 Computing Fundamental Notes for Thursday, October 5, 2017
Repetition-Sentinel,Flag Loop/Do_While
Repetition.
Lecture 07 More Repetition Richard Gesick.
Computer Science 101 While Statement.
Lecture 4B More Repetition Richard Gesick
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Learning to Program in Python
Please use speaker notes for additional information!
More Loops.
Loops A portion of a program that repeats a statement or a group of statements is called a loop. The statement or group of statements to be repeated is.
Chapter 8 The Loops By: Mr. Baha Hanene.
Java Programming Loops
Higher Computing Using Loops.
Do While (condition is true) … Loop
Introduction to TouchDevelop
For Loops.
Module 4 Loops.
Lec 4: while loop and do-while loop
Do … Loop Until (condition is true)
random number between 1 and 5.
3.1 Iteration Loops For … To … Next 18/01/2019.
Loop Strategies Repetition Playbook.
Writing Functions( ) (Part 4)
Python programming exercise
Arrays.
Programs. at the code at the site..
A LESSON IN LOOPING What is a loop?
How can you make a guessing game?
Java Programming Loops
Integers.
How can you make a guessing game?
Little Man Computer (continued).
Dry Run Fix it Write a program
Learning Intention I will learn about the standard algorithm for input validation.
Linear sequences A linear sequence is a list of numbers that have a common difference between each number in the list. Finding the rule that can extend.
This shows running the first guess number program which only allows one guess - I show the correct answer for testing purposes.
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
Basic program gives only one quess and then the program ends.
Programming Fundamental
Presentation transcript:

More Loops

While loops review while(condition(s)) { // body of the loop } Loop will execute until the condition is false

Do While loop do { // body of the loop } while(condition(s)) Exact same as while loop except the difference is that the loop condition is tested at the end. That means the body of the loop is run at least once.

Exercise 1 Use a do while loop to display every number between 0-100, put a space between each one, no end line.

Exercise 2 Declare an integer num1 = 1000 Exercise 2 Declare an integer num1 = 1000. Use a do while loop to keep asking for a number between 0-100. Every time a number is entered, take that number and subtract it from num. Keep going until the value of num1 is less than 0.

Exercise 3 Generate a random number from 100 – 1000 Exercise 3 Generate a random number from 100 – 1000. Ask the user to guess that number. If the guess is below that number, say “go higher.” If the guess is above that number, say “go lower.” Keep asking for a guess until the random number is correctly guessed.

Exercise 4 Ask the user for three integer inputs and keep adding them together until you hit a number that can be evenly divided by 10. Each loop will add to the value of the previous loop. Let us know how many times you had to do the loop until you hit that number and what that number is.