Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.

Slides:



Advertisements
Similar presentations
Programming with Microsoft Visual Basic th Edition
Advertisements

Programming Logic and Design Eighth Edition
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Programming Logic and Design, Third Edition Comprehensive
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Repeating Actions While and For Loops
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
Looping Yong Choi School of Business CSU, Bakersfield.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Programming Logic and Design Fifth Edition, Comprehensive
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Loops George Mason University. Loop Structure Loop- A structure that allows repeated execution of a block of statements Loop body- A block of statements;
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
A FIRST BOOK OF C++ CHAPTER 5 REPETITION. OBJECTIVES In this chapter, you will learn about: The while Statement Interactive while Loops The for Statement.
A First Book of C++ Chapter 5 Repetition.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Controlling Program Flow with Looping Structures
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
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 Looping 5. The Increment and Decrement Operators 5.1.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
1 Fall 2009ACS-1903 Ch 4 Loops and Files while loop do-while loop for loop Other topics later on …
Chapter 6: Looping. Objectives Learn about the loop structure Create while loops Use shortcut arithmetic operators Create for loops Create do…while loops.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
1 Looping Chapter 6 2 Getting Looped in C++ Using flags to control a while statement Trapping for valid input Ending a loop with End Of File condition.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
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.
Lecture 4b Repeating With Loops
REPETITION CONTROL STRUCTURE
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Unit 3 Lesson 9 Repetition Statements (Loops)
Programming Logic and Design Fourth Edition, Comprehensive
CHAPTER 5A Loop Structure
Chapter 5: Repetition Structures
JavaScript: Control Statements.
Topics Introduction to Repetition Structures
Learning About the Loop Structure (continued)
Outline Altering flow of control Boolean expressions
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Chapter 8: More on the Repetition Structure
Chapter 6: Repetition Statements
Topics Introduction to Repetition Structures
PROGRAM FLOWCHART Iteration Statements.
Learning Plan 4 Looping.
Presentation transcript:

Chapter 5: Looping

Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements within a looping structure C# types of loops: – while loop – for loop – do loop (or do...while loop) 2Microsoft Visual C# 2012, Fifth Edition

Using the while Loop (cont’d.) 3Microsoft Visual C# 2012, Fifth Edition

Using the while Loop (cont’d.) while loop – Used to execute a body of statements continuously as long as some condition continues to be true Infinite loop – A loop that never ends Making a while loop end correctly – Initialize the loop control variable – Test the control variable in the while expression – Alter the value of the control variable in the code block 4Microsoft Visual C# 2012, Fifth Edition

Using the while Loop (cont’d.) 5Microsoft Visual C# 2012, Fifth Edition

Using the while Loop (cont’d.) 6Microsoft Visual C# 2012, Fifth Edition

Using the while Loop (cont’d.) 7Microsoft Visual C# 2012, Fifth Edition

8 Using the while Loop (cont’d.)

Empty body – A body with no statements in it Alter the control variable by: – Incrementing, or adding to it – Decrementing, or subtracting from it Definite loop or counted loop – A loop for which the number of iterations is predetermined Indefinite loop – The value of a loop control variable is not altered by arithmetic, but instead is altered by user input 9Microsoft Visual C# 2012, Fifth Edition

Using the while Loop (cont’d.) 10Microsoft Visual C# 2012, Fifth Edition

Using the for Loop for loop – A shorthand way to create definite loops Sections of the loop – Control variable initialization – Control variable testing – Control variable updating 11Microsoft Visual C# 2012, Fifth Edition

Using the for Loop (cont’d.) 12Microsoft Visual C# 2012, Fifth Edition

Using the do Loop do loop – Checks at the “bottom” of the loop after one repetition has occurred – Convenient when you know you want to perform some task at least one time 13Microsoft Visual C# 2012, Fifth Edition

14Microsoft Visual C# 2012, Fifth Edition Using the do Loop (cont’d.)

15Microsoft Visual C# 2012, Fifth Edition

Using Nested Loops When loops are nested, each pair contains an inner loop and an outer loop – The inner loop must be entirely contained within the outer loop – Loops can never overlap 16Microsoft Visual C# 2012, Fifth Edition

Using Nested Loops (cont’d.) 17Microsoft Visual C# 2012, Fifth Edition

18Microsoft Visual C# 2012, Fifth Edition

19 Microsoft Visual C# 2012, Fifth Edition

Accumulating Totals Totals are accumulated – Gathered together and added into a final sum by processing individual records one at a time in a loop 20Microsoft Visual C# 2012, Fifth Edition

Accumulating Totals (cont’d.) 21Microsoft Visual C# 2012, Fifth Edition

Accumulating Totals (cont’d.) 22Microsoft Visual C# 2012, Fifth Edition

Looping Issues in GUI Programs Using a loop within a method in a GUI application is no different from using one in a console application Event-driven programs sometimes require fewer coded loops – Some events are determined by the user’s actions when the program is running, rather than by the programmer’s coding 23Microsoft Visual C# 2012, Fifth Edition

24Microsoft Visual C# 2012, Fifth Edition Looping Issues in GUI Programs (cont’d.)

25Microsoft Visual C# 2012, Fifth Edition Looping Issues in GUI Programs (cont’d.)

26Microsoft Visual C# 2012, Fifth Edition Looping Issues in GUI Programs (cont’d.)

27Microsoft Visual C# 2012, Fifth Edition Looping Issues in GUI Programs (cont’d.)