Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Programming Right from the Start with Visual Basic .NET 1/e"— Presentation transcript:

1 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

2 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

3 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

4 3-1 Console Input and Output

5 3-1 Console Input and Output (cont.)

6 3-1 Console Input and Output (cont.)

7 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.

8 Console End-of-Output Character (cont.)

9 Console End-of-Output Character (cont.)

10 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.

11 3-2 For Loops (cont.)

12 3-2 For Loops (cont.)

13 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

14 Counters and Accumulators (cont.)

15 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.

16 Validating Input

17 Validating Input (cont.)

18 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.

19 Grocery Checkout Revised (cont.)

20 Grocery Checkout Revised (cont.)

21 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.

22 Exit Loop (cont.)

23 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.

24 3-4 Nested Loops (cont.)

25 3-4 Nested Loops (cont.)

26 Triangle Problem

27 Triangle Problem (cont.)

28 Triangle Problem (cont.)

29 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.

30 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.

31 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.

32 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


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

Similar presentations


Ads by Google