Decision statements

VB.NET provides 3 decision statement

  1. If ..then
  2. Syntax:
    If Expression1 Then
    ‘This statement block is executed if Expression1 is true
    End If

  3. If..then..else
  4. Syntax:
    If Expression1 Then
    ‘This statement block is executed if Expression1 is true
    Else
    ‘This statement block is executed if Expression1 is
    false
    End If

  5. Select..Case
  6. Syntax:
    Select Expression1
    case 1
    ‘ statement block for case 1
    case 2
    ‘ statement block for case 2
    case n
    ‘ statement block for case n
    case Else
    ‘ statement block if none of the case match
    End Select

Loop structures supported by VB. NET

  1. While
  2. Syntax:
    While Expression
      Statement block
    End While
    Dim Counter As Integer = 0
    Dim Number As Integer = 10
    While Number > 6
    Number = Number – 1
    Counter = Counter + 1
    End While



    Example:
    Dim Counter As Integer = 0
    Dim Number As Integer = 10
    While Number > 6
    Number = Number – 1
    Counter = Counter + 1
    End While


  3. Do..Loop
  4. Syntax:
    Do
       Statement Block
    Loop While Expression



    Example:
    Dim Counter As Integer =0
    Dim Number As Integer =10
    Do While Number > 6
    Number = Number - 1
    Counter = Counter + 1
    Loop


  5. For..Next
  6. Syntax:
    For Loop Counter = Start Value To End Value [Step value]
       ‘statement block
    Next [Loop Counter]


    Example:
    Dim J, Total As Integer
    For J = 2 To 10 Step 2
    Total = Total + J
    Next J

What is Form? << Previous
Next >> Arrays

Our aim is to provide information to the knowledge


comments powered by Disqus






Footer1