1 CS 105 Lecture 6 While Loops Wed, Feb 16, 2011, 5:13 pm.

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 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?
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Programming Switch command. COMP102 Prog. Fundamentals: Switch command / Slide 2 Multiple Selection: The switch Statement value1 action 1 value2 action.
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.
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.
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.
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
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
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.
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Switch Statement in C++. Syntax switch (selector) { case L1: statements1; break; case L2: statements2; break; … default: statements_n; } Semantics: This.
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.
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 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Announcements Exam 1 Tuesday July minutes 10 % of Total Grade Covers Everything through Lecture 05. –Includes Quiz 1 Topics (terminology, variables,
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.
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.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Chapter 05 (Part III) Control Statements: Part II.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
C++ Programming Lecture 7 Control Structure I (Selection) – Part II The Hashemite University Computer Engineering Department.
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)
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.
Computer Programming -1-
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Infinite for Loop If you omit the test condition, the value is assumed to be TRUE so the loop will continue indefinitely unless you provide some other.
C++ Iterative Constructs
CS 1430: Programming in C++ No time to cover HiC.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Engineering Problem Solving with C++, Etter/Ingber
Branching Constructs Review
Programming Fundamentals
Chapter 2.2 Control Structures (Iteration)
Announcements Exam 1 Grades Posted on Blackboard.
Conditinoal Constructs Review
For & do/while Loops.
Selection (if-then-else)
Conditinoal Constructs Review
Counting Loops.
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)
Chapter 4: Control Structures I (Selection)
Control Structures Part 3
Looping III (do … while statement)
Let’s all Repeat Together
do/while Selection Structure
Fundamental Programming
Decisions, decisions, decisions
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
Announcements Exam 1 Grades Posted on blackboard Average: 83.26
Presentation transcript:

1 CS 105 Lecture 6 While Loops Wed, Feb 16, 2011, 5:13 pm

2 Switch Statements Also called switch/case statement Just "case" in other languages Selects among several different actions Can only select from integer or character If an integer value is matched, statements under control of that case block are executed.

3 Switch/Case Example int numPassengers; cout << “Enter Passengers: “; cin >> numPassengers; switch (numPassengers) { case 0: zeroPassengers(); break; case 1: onePassenger(); break; default: manyPassengers(); break; }

4 Switch/Case Example char menuItem; cout << "Enter Menu Selection: "; cin >> menuItem; switch (menuItem) { case 'O': orderFunction(); break; case 'C': checkoutFunction(); break; default: errorFunction(); break; }

5 Iteration Iteration (Looping): Performing a series of statements multiple times until some condition is met. Eliminates the need for redundant coding or function calls Multiple ways to loop in C++

6 Syntaxes:  while (condition) statement;  while (condition) { statement; statement; } The while Loop

7 while Loop With Counter const int MAX = 100; int counter = 0; while (counter < MAX) { cout << counter << “ “ << endl; counter++; }

8 while Loop With Limit Read- In int numEmployees,curNum = 0; cout << “Enter Number of Employees: “; cin >> numEmployees; if (numEmployees > 0) { while (curNum < numEmployees) { cout << “Welcome to CorpLand!” << endl; curNum++; }