VB.NET Technology

VB.Net Projects

VB.Net Project 1

Control Statement
Previous Home Next
adplus-dvertising

The if Statement

If statement is used to take different paths of logic, depending on the conditions.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, 
	ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text >= 80 Then
            MessageBox.Show("Got Higher First Class ")
        ElseIf TextBox1.Text >= 60 Then
            MessageBox.Show("Got First Class ")
        ElseIf TextBox1.Text >= 40 Then
            MessageBox.Show("Just pass only")
        Else
            MessageBox.Show("Failed")
        End If
    End Sub
End Class

The switch Statement

Another form of selection statement is the switch statement, which executes a set of logic depending on the value of a given parameter. The types of the values a switch statement operates on can be booleans, enums, integral types, and strings.

The while Loop

While loop is used to check a condition and then continues to execute a block of code as long as the condition evaluates to a boolean value of true.

Syntax

while (<boolean expression>)
      {
         <statements>
      }

When the boolean expression evaluates to false, the while loop statements are skipped and execution begins after the closing brace of that block of code.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, 
	ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = Integer.Parse(TextBox1.Text.ToString())
        While i < 10
            MessageBox.Show("I am in While statement ")
            i += 10
        End While
    End Sub
End Class

The do-while Loop

It works like a while loop, except that the syntax of the for loop includes initialization and condition modification. for loops are appropriate when you know exactly how many times you want to perform the statements within the loop. The contents within the for loop parentheses hold three sections separated by semicolons .

(<initializer list>; <boolean expression>; <iterator list>) { <statements> }

Module Module1
    Sub Main()
        For i As Integer = 0 To 19
            If i = 10 Then
                Exit For
            End If
            If i Mod 2 = 0 Then
                Continue For
            End If
            Console.Write("{0} ", i)
        Next
        Console.WriteLine()
    End Sub
End Module

Foreach Statement

The foreach statement is new to the C family of languages; it is used for looping through the elements of an array or a collection.

Module Module1
    Sub Main()
        Dim num As Integer() = New Integer() {0, 1, 2, 3, 4, 5, _
 6, 7, 8}
        For Each i As Integer In num
            System.Console.WriteLine(i)
        Next
    End Sub
End Module
Previous Home Next