Do-While Loops A do-while loop is always guaranteed to iterate at least once. This is because the condition is evaluated at the end of the loop, instead.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 5 new The Do…Loop Statement
by Chris Brown under Prof. Susan Rodger Duke University June 2012
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Even more problems.. Mean (average) I need a program that calculates the average of student test scores. I need a program that calculates the average.
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
QUIZ: FRIDAY! Waffle Wednesday: Tuesday. Do-While Loops A do-while loop is always guaranteed to iterate at least once. This is because the condition is.
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.
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.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
REPETITION CONTROL STRUCTURE
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
BIT116: Scripting Loops.
Loop Structures.
Variables, Expressions, and IO
Open AvgLoop. It should provide SOME guidance for today’s assignment, but don’t just copy-paste….THINK.
Lecture 07 More Repetition Richard Gesick.
Lecture 4B More Repetition Richard Gesick
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
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.
Chapter 6 The while Statement
Arrays, For loop While loop Do while loop
Looping and Repetition
Chapter 5 The Do…Loop Statement
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Please use speaker notes for additional information!
More Loops.
Java Language Basics.
COMP 110 Loops, loops, loops, loops, loops, loops…
Teaching London Computing
Java Programming Loops
4. sequence data type Rocky K. C. Chang 16 September 2018
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
Loops CIS 40 – Introduction to Programming in Python
4.1 Strings ASCII & Processing Strings with the Functions
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
LOOPS BY: LAUREN & ROMEO.
Do … Loop Until (condition is true)
3.5- The while Statement The while statement has the following syntax:
Chapter 6: Repetition Statements
3.1 Iteration Loops For … To … Next 18/01/2019.
Lesson 1 Notes Chapter 6.
Computing Fundamentals
Arrays.
Note the rights settings.
Chapter 3: Selection Structures: Making Decisions
Flowcharts and Pseudo Code
Objectives You should be able to describe: The while Statement
Java Programming Loops
Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Loops.
Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Looping and Repetition
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Presentation transcript:

Do-While Loops A do-while loop is always guaranteed to iterate at least once. This is because the condition is evaluated at the end of the loop, instead of the beginning (as is done in while and for loops). Note: a do-while loop is the only loop that requires a semi-colon. Demo: DoWhileDemo

Sentinels A sentinel is a value that the user can enter in order to stop the loop Usually seen in while or do-while loops Demo: Sentinel

Java’s Math class Allows you to do basic math functions Not necessary to import it 3 methods you must know: Math.abs(num) // find the absolute value of num Math.pow(base, exp) // raises base to the exp power Math.sqrt(num) // finds the square root of num Demo: MathDemo

Open Powerpoint 1.5 – review the String examples, especially the substring method. Also open the assignment Middle

Assignment: QBrating Click here for the NFL QB Rating Formula. Write a program that asks the user for an NFL QB’s stats (completions, attempts, yards, TDs, and interceptions). Then, click here for Peyton Manning’s 2014 stats, and use them to make sure that your program displays his correct QB rating (101.5). ***On the QB rating page, take note of the line “a, b, c, and d can not…” – this means that if any of them exceed 2.375, then you must set it equal to 2.375, and if any fall below 0, you must set it to 0. Once the program works properly, add a do-while loop that wraps around much of the code so that after calculating a QB Rating, you ask the user (yes/no) if they would like to look up another. The user should be able to repeat the process as many times as they want to. If the user looks up 3 or more QB Ratings, you should start displaying “WHY?” every time you display the rating. If a QB rating is over 120 or under 20, display “system crash” and stop the loop from iterating. (see next slide)

Assignment (Stannis) Prompt the user to enter their first & last name (using 1 variable, not separately). Then…. Error check: If the user forgot to enter a space, make them try again until they get it right. Display the number of characters in the name (not including the space). Display the first letter, the third letter, and the last letter (of the full name). Display the name in all caps. If the letters A and Z (uppercase) are both in the name, display “both.” Display the characters from index #4 to (and including) index #6 Display the characters from index #2 to the end of the name Display the person’s initials only. Using a do-while loop, display each character in the person’s name on separate lines.