© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Slides:



Advertisements
Similar presentations
CSC 221: Computer Programming I Fall 2001  conditional repetition  repetition for: simulations, input verification, input sequences, …  while loops.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Lecture 2 Introduction to C Programming
Introduction to C Programming
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Do/while Structure (L15) * do/while structure * break Statement * continue Statement * Loop Programming Techniques - Interactive input within a loop -
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Chapter 5: Loops and Files.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Introduction to C Programming
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Chapter 2 Control. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Repetition, quick overview.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
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.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved. Chapter 4 Slide #1.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students, continue; and break; statements.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Loop. 3.1Introduction to Repetition Structures Loop – a block of code that, under certain conditions will be executed repeatedly. Do Prompt for and input.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Lecture 4b Repeating With Loops
Review 1.
Chapter 6: Loops.
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
Chapter 4 C Program Control Part I
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Chapter 5: Loops and Files.
Chapter 2.2 Control Structures (Iteration)
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Control Structure Senior Lecturer
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Looping and Repetition
Iteration with While You can say that again.
MSIS 655 Advanced Business Applications Programming
Debugging October 3, 2007 ComS 207: Programming I (in Java)
Outline Altering flow of control Boolean expressions
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Iteration: Beyond the Basic PERFORM
LOOPS BY: LAUREN & ROMEO.
Chapter 6 Control Statements: Part 2
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Ltd. All rights reserved.
What output is produced by the following fragment?
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Debugging October 4, 2006 ComS 207: Programming I (in Java)
Chapter 4: Repetition Structures: Looping
Programming Right from the Start with Visual Basic .NET 1/e
Repetition Statements (Loops) - 2
Based on slides created by Bjarne Stroustrup & Tony Gaddis
PROGRAM FLOWCHART Iteration Statements.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Chap 7. Advanced Control Statements in Java
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)
Chapter 13 Conditional Repetition
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
Chapter 8 JavaScript: Control Statements, Part 2
Looping and Repetition
break & continue Statements
Presentation transcript:

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Section 3 Chapter 3 © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Executes a block of code repeatedly while loop repeatedly executes an indented block of statements As long as a certain condition is met Form Continuation condition is a boolean expression © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Example 1: Program displays 1 – 5, after loop terminates, num will be 6 © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

The while Loop FIGURE 3.22 Flowchart for Example 1. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Example 2: Input validation. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Example 3: Find min, max, average. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Example 3: Find min, max, average. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Example 4: Stores the numbers in a list, and then uses list methods and functions to determine the requested values. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The while Loop Example 5: Determines when bank deposit reaches one million dollars © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The break Statement Causes an exit from anywhere in the body of a loop When break is executed Loop immediately terminates Break statements usually occur in if statements © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The break Statement Example 6: Program uses break to avoid two input statements. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

The break Statement FIGURE 3.23 Flowchart for Example 6 © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

The continue Statement When continue executed in a while loop Current iteration of the loop terminates Execution returns to the loop’s header Usually appear inside if statements. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

The continue Statement Example 7: Searches a list for the first int object that is divisible by 11. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Creating a Menu Example 8: Uses a menu to obtain facts about the United States. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

The continue Statement Example 8: Uses a menu to obtain facts about the United States. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Infinite Loops Example 9: Condition number >= 0 always true. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

Infinite Loops FIGURE 3.24 Program Containing an Infinite Loop. © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. End Section 3 Chapter 3 © 2016 Pearson Education, Inc., Hoboken, NJ.  All rights reserved.