3 - Program Flow Control
3 - Program Flow Control
3 - Program Flow Control
If the contition is TRUE then the control goes to between IF and Else
block , that is the program will execute the code between IF and
ELSE statements.
If the contition is FLASE then the control goes to between ELSE and
END IF block , that is the program will execute the code between
ELSE and END IF statements.
If you want o check more than one condition at the same time , you
can use ElseIf .
If [your condition here]
Your code here
ElseIf [your condition here]
Your code here
ElseIf [your condition here]
Your code here
Else
Your code Here
End If
1) If the marks is greater than 80 then the student get higher first
class
2) If the marks less than 80 and greater than 60 then the student
get first class
3) If the marks less than 60 and greater than 40 then the student
get second class
4) The last condition is , if the marks less than 40 then the student
fail.
If you want to check a condition within condition you can use nested
if statements
When you execute this program you will get in messagebox "Failed "
endValue : When the counter variable reach end value the Loop will
stop .
1. startVal=1
2. endVal = 5
3. For var = startVal To endVal
4. show message
5. Next var
Line 3: Assign the starting value to var and inform to stop when the
var reach endVal
Line 5: Taking next step , if the counter not reach the endVal
When you execute the above source code , the program shows the message box only
three times .
FOR EACH Loop usually using when you are in a situation to execute
every single element or item in a group (like every single element in
an Array, or every single files in a folder or , every character in a
String ) , in these type of situation you can use For Each loop.
LoopBody : The code you want to execute within For Each Loop
Let's take a real time example , if you want to display the each
character in the website name "HTTP://NET-INFORMATIONS.COM" ,
it is convenient to use For Each Loop.
1. siteName = "HTTP://NET-INFORMATIONS.COM"
2. For Each singleChar In siteName
3. MsgBox(singleChar)
4. Next
Line 2: This line is extracting the single item from the group
When you execute this program you will get each character of the string in
Messagebox.
While [condition]
[loop body]
End While
1. counter = 1
2. While (counter <= 10)
3. Message
4. counter = counter + 1
5. End While
Line 3: Each time the Loop execute the message and show
Line 4: Counter increment the value of 1 each time the loop execute
When you execute the program 10 times the message shows with counter and exit
from the While .. End While loop.
Syntax:
Enum declaration
Enum Temperature
Low
Medium
High
End Enum
Initializing Members
You can specify another integral numeric type by using a colon. The
following Enum declare as byte, you can verify the underlying
numeric values by casting to the underlying type.
Enum.Parse in VB.Net
Output is : green
Ex:
Method 2: