Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Looping Structures: Do Loops
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Lecture Notes 3 Loops (Repetition)
If Statements & Relational Operators Programming.
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.
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.
Iterative Constructs – chapter 4 pp 189 to 216 This lecture covers the mechanisms for deciding the conditions to repeat action. Some materials are from.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
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%
Loops. COMP104 Loops / Slide 2 Shortcut Assignment * C++ has a set of operators for applying an operation to a variable and then storing the result back.
Structured Programming Programming. COMP102 Prog Fundamentals I: Structured Programming /Slide 2 Structured Programming l Structured programing is the.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
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.
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
If Statements & Relational Operators, Part 2 Programming.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Simple Control Structures IF, IF-ELSE statements in C.
CONTROLLING PROGRAM FLOW
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
LOOPS In the Name of Allah The Most Merciful The Most Compassionate LOOPS
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
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.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Follow up from lab See Magic8Ball.java Issues that you ran into.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Identify the Appropriate Method for Handling Repetition
Branching Constructs Review
Chapter 5: Loops and Files.
CiS 260: App Dev I Chapter 4: Control Structures II.
Programming Fundamentals
Intro to Programming Week # 5 Repetition Structure Lecture # 9
Chapter 4 Repetition Structures
For Loops October 12, 2017.
Conditinoal Constructs Review
Loops October 10, 2017.
Alternate Version of STARTING OUT WITH C++ 4th Edition
Loops (iterations, repetitions)
Conditinoal Constructs Review
Control Structures Part 1
Loops Prof.Gaikwad Varsha P. Information Technology Dept.
Alternate Version of STARTING OUT WITH C++ 4th Edition
A LESSON IN LOOPING What is a loop?
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Statements in C Programming
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Week 3 – Repetition (ctd.)
Presentation transcript:

do-while Loops Programming

COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it works: n execute action n if condition is true then execute action again n repeat this process until condition evaluates to false. l action is either a single statement or a group of statements within braces. action true false condition

COMP102 Prog Fundamentals I: do-while Loops /Slide 3 N! int number, factorial, counter; cout > number; factorial = 1; counter = 1; do{ factorial *= counter; counter++; }while(counter <= number); cout << "The factorial of " << number << " is " << factorial << endl;

COMP102 Prog Fundamentals I: do-while Loops /Slide 4 2N2N int number, result, counter; cout > number; result = 1; counter = 1; do{ result *= 2; counter++; }while (counter <= number); cout << "Two raised to the " << number << " power is " << result << endl;

COMP102 Prog Fundamentals I: do-while Loops /Slide 5 Maximum int value;// input value int max=0;// maximum value do{ cout << "Enter a positive number “ > value; if(value > max) max = value; }while(value!=-1); cout << "The maximum value found is " << max << endl;

COMP102 Prog Fundamentals I: do-while Loops /Slide 6 Waiting for a Reply char reply; do{ // do something cout << "Continue(y/n): "; cin >> reply; }while(reply!='n');