Download presentation

Presentation is loading. Please wait.

Published byBrooke Munoz Modified over 3 years ago

1
Chapter 6 - VB 2005 by Schneider1 Sample Dim i As Integer For i = 1 To 5 lstTable.Items.Add(i & " " & i ^ 2) Next The loop control variable, i, is Initialized to 1 Tested against the stop value, 5 Incremented by 1 at the Next statement

2
Chapter 6 - VB 2005 by Schneider2 For…Next Loop Syntax

3
Uthaisombut & Schneider3 Set control variable to initial value Execute Statements in loop body Increment control variable Is control variable > terminating value? Execute statements following the loop Yes No

4
Chapter 6 - VB 2005 by Schneider4 Example 2 For index = 0 To n Step s lstValues.Items.Add(index) Next Control variable Start value Stop value Amount to add to index

5
Chapter 6 - VB 2005 by Schneider5 Example with Negative Step Dim j As Integer For j = 10 To 1 Step -1 lstBox.Items.Add(j) Next lstBox.Items.Add("Blastoff")

6
Chapter 6 - VB 2005 by Schneider6 Declaration Inside For Statement Dim i As Integer For i = 1 To 5 lstTable.Items.Add(i & " " & i ^ 2) Next For i As Integer = 1 To 5 lstTable.Items.Add(i & " " & i ^ 2) Next

7
Chapter 6 - VB 2005 by Schneider7 Nested For…Next Loops

8
Chapter 6 - VB 2005 by Schneider8 For and Next Pairs For and Next statements must be paired. If one is missing, the automatic syntax checker will complain with a wavy underline and a message such as A For must be paired with a Next.

9
Chapter 6 - VB 2005 by Schneider9 Start, Stop, and Step values Consider a loop beginning with For i As Integer = m To n Step s. The loop will be executed exactly once if m equals n no matter what value s has. The loop will not be executed at all if m is greater than n and s is positive, or if m is less than n and s is negative.

10
Loop in Action For i = 1 to 4 Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider10

11
Loop in Action For i = 1 to 4 Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider11 Value of i Picture1 Output

12
Loop in Action For i = 1 to 4 Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider12 Value of i 1 Picture1 Output 2

13
Loop in Action For i = 1 to 4 Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider13 Value of i 2 Picture1 Output 2 4

14
Loop in Action For i = 1 to 4 Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider14 Value of i 3 Picture1 Output 2 4 6

15
Loop in Action For i = 1 to 4 Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider15 Value of i 4 Picture1 Output 2 4 6 8

16
Loop in Action For i = 1 to 4 x = i mod 5 storeMe(i) Picture1.print i * 2 Next Chapter 6 - VB 2005 by Schneider16

Similar presentations

OK

Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.

Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on natural and artificial satellites orbiting Ppt on animal kingdom class 9 Ppt on solar system for class 6 download Ppt on bluetooth hacking windows Ppt on operating system by galvin Ppt on foundation course Ppt on expansion of british rule in india Ppt on 500 mw turbo generators Ppt on fourth and fifth state of matter summary Ppt on area of triangle