Programming Right from the Start with Visual Basic .NET 1/e

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

Chapter 6: The Repetition Structure
Programming Logic and Design Eighth Edition
Programming Logic and Design, Third Edition Comprehensive
Objectives In this chapter, you will learn about:
Repeating Actions While and For Loops
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
An Introduction to Programming with C++ Fifth Edition
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
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.
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.
Chapter 6: The Repetition Structure
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.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
+ 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)
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 5 Control Structures II: Repetition.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
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.
Follow up from lab See Magic8Ball.java Issues that you ran into.
ECE Application Programming
Chapter 4 – C Program Control
REPETITION CONTROL STRUCTURE
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
ECE Application Programming
Chapter 5: Control Structures II
Chapter 5: Control Structures II
Programming Logic and Design Fourth Edition, Comprehensive
Chapter 5: Control Structures II
CHAPTER 5A Loop Structure
Control Structures II (Repetition)
Chapter 5: Repetition Structures
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Java Programming: Guided Learning with Early Objects
Ch 7: JavaScript Control Statements I.
JavaScript: Control Statements I
While Loops Chapter 3.
Chapter 5: Control Structures II
Lecture 4B More Repetition Richard Gesick
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Control Structure Senior Lecturer
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Control Structure Senior Lecturer
Additional Control Structures
A First Book of ANSI C Fourth Edition
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Chapter 2.1 Repetition.
Control Statements Loops.
Chapter 6: Repetition Statements
© 2016 Pearson Education, Ltd. All rights reserved.
Seating “chart” Front - Screen rows Back DOOR.
Chapter 4: Repetition Structures: Looping
Control Statements Loops.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Looping and Repetition
Presentation transcript:

Programming Right from the Start with Visual Basic .NET 1/e 3 Repeating Actions Programming Right from the Start with Visual Basic .NET 1/e

Objectives Understand how console input and output (console I/O) work Understand and use the For loop statement Understand and use the While loop statement

Objectives (cont.) Understand and use the Exit loop statement Understand and use counters and accumulators Develop and evaluate solutions that require loops and nested loops

3-1 Console Input and Output

3-1 Console Input and Output (cont.)

3-1 Console Input and Output (cont.)

Console End-of-Output Character The ending position of the current output is indicated with the end-of-output symbol (§). The end-of-output symbol is only visible when editing the console output expression.

Console End-of-Output Character (cont.)

Console End-of-Output Character (cont.)

3-2 For Loops For loops are used to repeat actions a predetermined number of times. The loop element displays the loop variable, initial value, and final value.

3-2 For Loops (cont.)

3-2 For Loops (cont.)

Counters and Accumulators Counters are variables that keep track of how many times a statement has executed. Counter = Counter + 1 Accumulators are variables that maintain a running total. Accumulator = Accumulator + NewValue

Counters and Accumulators (cont.)

3-3 While Loops While loops are used when an action is to be repeated an unknown number of times. A pre-test loop tests the looping condition before executing the body of the loop. A post-test loop guarantees at least one execution of the loop body regardless of the condition.

Validating Input

Validating Input (cont.)

Grocery Checkout Revised A sentinel value (or signaling value) is used to indicate the end of input. The solution flowchart in Figure 3-11 shows -1 as the sentinel value.

Grocery Checkout Revised (cont.)

Grocery Checkout Revised (cont.)

Exit Loop In addition to processing the valid data, the sentinel value must also be identified and handled. This is known as the loop-and-a-half problem. An Exit loop causes control to jump out of the loop to the statement immediately below the loop.

Exit Loop (cont.)

3-4 Nested Loops For loops and While loops both allow code inside the body of the loop to be repeated many times. A nested loop refers to a loop contained inside the body of another loop.

3-4 Nested Loops (cont.)

3-4 Nested Loops (cont.)

Triangle Problem

Triangle Problem (cont.)

Triangle Problem (cont.)

Chapter Summary Console I/O is persistent, meaning each line of input and output remains in the console window for the lifetime of the program. The end-of-output (§) always appears at the end of the console output expression.

Chapter Summary (cont.) For loops are used to repeat actions a predetermined number of times. While loops are used to repeat actions an unknown number of times. Counters and accumulators are variables typically used inside a loop to help calculate counts, totals, and averages.

Chapter Summary (cont.) The Exit loop statement causes control to jump directly to the statement following the current loop. A nested loop refers to a loop that appears inside the body of another loop.

Programming Right from the Start with Visual Basic .NET 1/e 3 Repeating Actions Programming Right from the Start with Visual Basic .NET 1/e