If … Then … ElseIf Structure in Visual Basic 2010

If … Then … ElseIf Structure in Visual Basic 2010

Decision Making Structures:

Decision making structures are very popular in programming languages. They help the program to take certain decisions based on certain conditions. These conditions vary being true or false while you test them. Below you can check how a general format of a decision making structure looks like.

Pic One ElseIf

The main Decision Making Structures used in Visual Basic programming can be:

  1. If Constructions (Simple If, If … Then … Else, If … ElseIf and Nested If)
  2. Select Case Construction
  3. Try … Catch Construction

Simple If Structure:

Simple If Structure or mostly called the If … Then Structure is the most common type of If Structure. It checks only one condition and executes one result based on it. It performs a specific action only when the condition given is true, otherwise the action is skipped away.

General Syntax:

Example Code: (We will check if a given number by the user is positive or not.)

Output:

Output 1Output 2

 

 

 

 

 

 

 

 

Check Also:   Pass By Reference & Optional Pass By Value

If … Then … Else Structure:

This structure acts the same as the simple if structure. Except that it will also generate an output if the condition is false.

General Syntax:

Example Code:

Output:

Output 3Output 4

 

 

 

 

 

 

 

 

Check Also:   Looping Structures in Visual Basic 2010

If … ElseIf Structure:

If … ElseIf is the same as the If … Then …. Else structure. But here various conditions are checked and based on the result outputs are generated. You can add as many ElseIf statements as you wish to.

General Syntax:

Code Example: (Grading students based on their percentage)

Note: In the code below, we have also made use of the Logical AND operator to check two conditions at the same time.

Output:

Output 5Output 6

 

 

 

 

 

 

 

 

Further; you can find articles on Decision Making Structures in Visual Basic 2010 @ CODEJOW

Moreover; feel free to ask your questions, post your comments and enquire about further articles.

Previous Pass By Reference & Optional Pass By Value in Visual Basic 2010
Next What is Method Overloading in Java?

About author

Bahonar Javid
Bahonar Javid 43 posts

<p>* Computer Application Student<br /> * Co-Founder of www.codejow.com<br /> * Love to code and Learn new languages<br /> * Enjoy playing football</p>

View all posts by this author →

You might also like