Continue Statement

You can use the Continue statement in a Do loop, a For loop, or a While loop to transfer execution to the next iteration within the loop. Listing 4.4 shows how to use a Continue statement to identify the number of styles in use in a Word document.

Listing 4.4. Using a Continue statement in a For loop Sub CountStyles()

Dim styleCount As Integer = 0

For Each currentStyle As Word.Style In Me.Styles

If currentStyle.InUse = False Then Continue For styleCount += 1


MsgBox("Total styles: " & Me.Styles.Count & vbCrLf & _ "Styles available: " & styleCount)

End Sub

In this code example, you use the += operator to add a value to a numeric variable and then assign the result to the variable. Using VBA, you type this:

styleCount = styleCount + 1

Using Visual Basic 2005, you can type the following to get identical functionality:

styleCount += 1

0 0

Post a comment