Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

CONDITIONAL

STATEMENTS, LOOPS AND


ARRAYS
Flow Control And Conditional
Statements

If…Then…Else statement:

If Boolean expression Then

Statement or block of statement

Else

Statement or block of statement

End If

If(boolean_expression 1)Then

' Executes when the boolean expression 1 is true

ElseIf( boolean_expression 2)Then

' Executes when the boolean expression 2 is true

ElseIf( boolean_expression 3)Then

' Executes when the boolean expression 3 is true

Else

' executes when the none of the above condition is true

End If
Select…Case statement

Select <any implicit data type expression>


Case expression
statements
' some other case blocks
...
Case Else
statements
End Select
 Select Case is a conditional statement, that helps you test a variable for equality against a set of
values.

 Syntax

 Select <any implicit data type expression>


 Case expression
 statements
 ' some other case blocks
 ...
 Case Else
 statements
 End Select
LOOPS IN VB.NET

For…Next Loop
For variable = startingValue To lastValue
statement or block of statements
Next
Example:
For i = 1 to 10
Console.WriteLine("value of i: {0}", i)
Next
Do While loop

Syntax:
Do { While | Until Do
} condition [ statements ]
[ Continue Do ]
[ statements ]
[ statements ]
[ Continue Do ] [ Exit Do ]
[ statements ] [ statements ]
Loop { While | Until } condition
[ Exit Do ]
[ statements ]
Loop
For each

Dim arr() As Integer = {1, 3, 5, 7, 9}


Dim a As Integer
'displaying the values

For Each a In arr


Console.WriteLine(a)
Next
while loop

It executes a series of statements as long as a given condition is True.


While condition
[ statements ]
[ Continue While ]
[ statements ] While a < 10
[ Exit While ] Console.WriteLine("value of a: {0}", a)
a=a+1
[ statements ]
End While
End While

You might also like