Announcements Exam 1 Tuesday July 14 60 minutes 10 % of Total Grade Covers Everything through Lecture 05. –Includes Quiz 1 Topics (terminology, variables,

Slides:



Advertisements
Similar presentations
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Advertisements

Branching Constructs Review l what are branching constructs? what type of branching constructs have we studied? l what is nested if? l what is multiway.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
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 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Announcements Quiz 1 Posted on blackboard Handed Back (and Gone Over)Next Monday “Only a Quiz” Counts 5% of Final Grade Exam 1 Counts 10%
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
1 CS 105 Lecture 6 While Loops Wed, Feb 16, 2011, 5:13 pm.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
Chapter 5: Control Structures II (Repetition)
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
1 CS 105 Lecture 5 Logical Operators; Switch Statement Wed, Feb 16, 2011, 5:11 pm.
1 CS 105 Lecture 7 For & Do-While Loops Sun, Feb 27, 2011, 2:16 pm.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
1 What is a loop? A loop is a repetition control structure that causes a single statement or block to be executed repeatedly Loops.
1 Chapter 9 Additional Control Structures Dale/Weems/Headington.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
CONTROLLING PROGRAM FLOW
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
1 Chapter 9 Additional Control Structures Dale/Weems.
1 Additional Control Structures. 2 Chapter 9 Topics  Switch Statement for Multi-way Branching  Do-While Statement for Looping  For Statement for Looping.
The for Loop Syntax: for ( expression1 ; condition ; expression2 ) statement ; for ( expression1 ; condition ; expression2 ) { statement ; } Same as: expression1.
1 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX do { Statement } while.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
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.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Overview Go over parts of quiz? Another iteration structure for loop.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Quiz 1 Exam 1 Next Monday. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) System.out.println(“You have an A!” ); else System.out.println(“You.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Sentinel Loops. while Syntax while(expression) statement.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
Topic 4: Looping Statements
REPETITION CONTROL STRUCTURE
Chapter 5: Control Structures II (Repetition)
Chapter 2.2 Control Structures (Iteration)
לולאות קרן כליף.
Announcements Exam 1 Grades Posted on Blackboard.
Selection (if-then-else)
Additional Control Structures
Chapter 7 Additional Control Structures
Announcements Exam 1 Thursday 50 minutes 10 % of Total Grade
Announcements Exam 1 Thursday Everything through Lab 5 50 minutes
Announcements Exam 1 Grades Posted on Blackboard.
Chapter 2.2 Control Structures (Iteration)
The for Loop Syntax: Same as: for (expression1;condition; expression2)
Summary Two basic concepts: variables and assignments Basic types:
Let’s all Repeat Together
do/while Selection Structure
Repetition Statements (Loops) - 2
(Dreaded) Quiz 2 Next Monday.
Announcements Exam 1 Grades Posted on blackboard Average: 83.26
Presentation transcript:

Announcements Exam 1 Tuesday July minutes 10 % of Total Grade Covers Everything through Lecture 05. –Includes Quiz 1 Topics (terminology, variables, constants, basics) –if-then-else –Compound statements –Relational operators –Logical operators –Switch/Case Statements –Precedence of Operators –DOES NOT INCLUDE LOOPS (Lect 06/07) 1

Iteration Iteration (Looping): Performing a Series of Statements Multiple Times until Some Condition Is Met. Eliminates the Need for Redundant Coding or Function Calls Many Ways to Loop in C++ 2

The while Loop Syntax: while ( condition ) statement ; while ( condition ) { statement ; } 3

while Example const int MAX = 100; int counter = 0; while (counter < MAX) { cout << counter << “ “ << endl; counter++; } 4

Example while Loop int numEmployees,curNum = 0; cout << “Enter Number of Employees: “; cin >> numEmployees; if (numEmployees > 0) { while (curNum < numEmployees) { cout << “Welcome to CorpLand!” << endl; curNum++; } 5

The for Loop Syntax: for ( expression1 ; condition ; expression2 ) statement ; for ( expression1 ; condition ; expression2 ) { statement ; } Same as: expression1 ; while ( condition ) { statement ; expression2 ; } 6

Example for Loop int numEmployees,curNum; cout << “Enter Number of Employees: “; cin >> numEmployees; if (numEmployees > 0) { for (curNum = 0; curNum < numEmployees;curNum++) { cout << “Welcome to CorpLand!” << endl; } 7

Looping for Input char letterEntered = ‘A’; while (letterEntered != ‘Z’) { cout << “Enter a letter: “; cin >> letterEntered; } 8

Looping until Flag bool noMoreData(); bool done = false; … while (!done) { … // do a bunch of stuff … if (noMoreData() == true) done = true; } cout << “We’re all through – thank you!”; 9

Nested Loops int i, j ; for (i=0; i < 10; i++) { for (j=0; j < 10; j++) { cout << i << j << “ “; } cout << endl; } 10

The do-while Loop Syntax do statement ; while (condition); do { statement ; } while (condition); 11

do-while Example int inputNum = 0; do { cout << “Please Input Number, –1 to quit: “; cin >> inputNum; } while (inputNum != -1); 12

What Is This? while (stringEntered != “apple”) { cout << “Enter a red fruit: “; cin >> stringEntered; } while (stringEntered != “banana”) { cout << “Enter a yellow fruit: “; cin >> stringEntered; } while (stringEntered != “pomegranate”) { cout << “Enter a random fruit: “; cin >> stringEntered; } 13

What Is This? for (i = 0; i < 10 ; i++) cout << “Interesting, isn’t it?” << endl; while (answer != ‘D’) { cout << “Enter an answer: “; cin >> answer; } while (answer != ‘D’) { cout << “Enter an answer: “; cin >> answer; } 14

What Is This? void kingsChair(int loopCounter) { int num; for(num = 0; num < loopCounter; num++) cout << “AAAAAAAAAAAAAAAAAAAAAAAAAA” << endl; } 15