[ ] Review Exam [ ] Questions [ ] Lab 6 [ ] HW6 [ ] Method Block Diagram [ ] Methods, methods [ ] Looping constructs [ ] for loop [ ] ++, -- (Thursday)

Slides:



Advertisements
Similar presentations
Control Structures.
Advertisements

Control Structures. Decision Making Structures The if and if…else are all selection control structures that introduce decision-making ability into a program.
1323Agenda3 HW int number = 716; System.out.println(“The number is “ + “number”); Valid variable name? two_shoes Flowchart symbols and clarity. “Single.
HFJ CHAPTER 5 REVIEW Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: What is the purpose of.
[ ] Questions [ ] Lab / HW Notes [ ] try/catch blocks – keep control [ ] Notes - Documentation – what was changed - names – single characters –no sentenceAnalysis.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
1 Chapter 6 Looping Dale/Weems/Headington. 2 l Physical order vs. logical order l A loop is a repetition control structure based on a condition. l it.
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
1 Three C++ Looping Statements Chapter 7 CSIS 10A.
Lec 4: while loop and do-while loop. Review from last week if Statements if (num < 0.5){...println("heads"); } if –else Statements if (num < 0.5){...println("heads");
& Decision Making Algorithms BY: Aakash Indurkhya.
Chapter 5: Control Structures II
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
The while-statement. The loop statements in Java What is a loop-statement: A loop-statement is a statement that repeatedly executes statements contained.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Designing with While loops.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
FOR LOOPS "LOOP FOR A SET NUMBER OF TIMES.". FOR ( START_VALUE; END_VALUE; INCREMENT_NUMBER ) { //YOUR_CODE_HERE } So after the word "for" (in lowercase)
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.
Follow up from lab See Magic8Ball.java Issues that you ran into.
CSE 110 Midterm Review Hans and Carmine. If Statements If statements use decision logic In order to properly use if statements relational operators must.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Chapter 9 Repetition.
CSC111 Quick Revision.
Chapter 4 Repetition Statements (loops)
Java for Beginners.
The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression,
Building Java Programs
Logical Operators and While Loops
Chapter 5 Repetition.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Conditional Loops.
Chapter 9 Control Structures.
Conditional Construct
More Loops.
More Loops.
Lecture Notes – Week 3 Lecture-2
Building Java Programs
Repetition Control Structure
Lec 4: while loop and do-while loop
CS 200 Loops Jim Williams, PhD.
What output is produced by the following fragment?
SELECTIONS STATEMENTS
Seating “chart” Front - Screen rows Back DOOR.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
General Condition Loop
Building Java Programs
Repetition Statements
PROGRAM FLOWCHART Iteration Statements.
Question 1a) What is printed by the following Java program? int s;
Repetition (While Loop) LAB 9
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Computer Science Club 1st November 2019.
Presentation transcript:

[ ] Review Exam [ ] Questions [ ] Lab 6 [ ] HW6 [ ] Method Block Diagram [ ] Methods, methods [ ] Looping constructs [ ] for loop [ ] ++, -- (Thursday) [ ] Examples [ ] Class exercise

Lab 6 Put loop logic in seuController main to exit only when user enters 9. analyzeSentence - how many words in sentence? consoleMethods class What about $ ? It blows up! We’ll catch that in a couple weeks.

Method Block Diagram seuController.java systemMethods.java seuCalculator.java consoleMethods.java

‘ask permission’

‘ask forgiveness’

while( ) { } Pre-condition loop user-controlled what goes in the blank spaces? What is the while-body?

// illustration of a ‘primer event’ with while Scanner cscan = new Scanner(System.in); int num1 = 0; System.out.println(“Please enter > 0: ”); num1 = cscan.nextInt(); while( !(num1 > 0 )) { System.out.println(“Invalid entry.”); System.out.println(“Please enter > 0: ”); num1 = cscan.nextInt(); } System.out.println(“Good work!”);

// illustration of a ‘loop controller’ (usually a boolean) Scanner cscan = new Scanner(System.in); int num1 = 0; boolean iAmNotHappy = true. while( iAmNotHappy) { System.out.println(“Please enter > 0: ”); num1 = cscan.nextInt(); if (num1 > 0) iAmNotHappy = false; else System.out.println(“Invalid entry.”); } System.out.println(“Good work!”);

do { } while( ); Post-condition loop user-controlled what goes in the blank spaces? What is the do-body?

do { System.out.println(“here we go ….”); } while( 1 == 1 ); Post-condition loop user-controlled What is the do-body?

int num = 0; num++ ++num num = num + 1 All these accomplish the same thing in the end. Specifically, they all increment num by 1. BUT – context is the conundrum int num2 = 5; num2++; int num3 = -3; num3 = --num2; int num4 = 5; num4 = num num3

int num4 = 5; System.out.println(num4++); System.out.println(“Really, num4 is “ + num4); int num5 = 5; System.out.println(“Hello “ + --num5); System.out.println(“Really, num5 is “ + num5); int num6 = 3; int num7 = -6; int num8 = 0; num8 = --num6 + num7++; System.out.println(“num8 is “ + num8);

for ( ; ; ) { } Pre-condition loop loop-controlled What is the ‘for-body’ Is the index automatically incremented? When? What goes in all the blank areas?

for ( starting index ;logical expression; index mover) { for body index++ } The ‘index mover’ is implicit – automatically done on way up. Note: DO NOT MUCK WITH AN INDEX

for ( int index = 0; index < 5; index++) { System.out.println(“hello!”); } Hand trace Output