Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

10 Conditional flow


'VB offers 6 basic methods of flow control

1. For ... Next
2. If ... Then
3. Select Case ... End Select
4. While ... Wend
5. Do ... Loop
6. Goto

'For ... Next =================================
For i = 1 To j Step k
  ...
Next i

'Example
For i = 1 To 10
    Print i
Next i

'If ... Then =================================
If (expression) Then
  ...
ElseIf (expression)
  ...
Else
  ...
End If

'Example
If j > 6 Then
   Print "big"
ElseIf i <> 32
   Print "hello"
Else
   Print "none of the above
End If

'Select Case ... End Select =================================
Select Case (expression)
   Case (variable list)
   Case (variable list)
   Case Else
End Select

'While ... Wend =================================
While (expression)
  ...
Wend

'Do ... Loop =================================
Do While | Until (expression)
  ...
Loop While | Until (expression)

For Each (variable) In (Collection)
Next

'Example
Do While j < 10
  j = j + 1
   Print J
Loop

'Example
Do
 j = j + 1
  Print J
Loop Until j = 25

'GoTo =================================
Goto Line

'Example
Goto Start   'skips the next two lines
j = j + 1
Print j
Start:
Print j