Sign In
Not register? Register Now!
You are here: HomeEssayIT & Computer Science
Pages:
2 pages/≈550 words
Sources:
5 Sources
Level:
MLA
Subject:
IT & Computer Science
Type:
Essay
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 10.8
Topic:

Compare And Contrast: If Else And Select Case In Visual Basic (Essay Sample)

Instructions:

Comparing and contrasting if-else and select case statements and explaining how they are used in Visual Basic.NET.

source..
Content:
Your Name
Instructor Name
Course Number
Date
COMPARE AND CONTRAST: IF ELSE AND SELECT CASE IN VISUAL BASIC
In visual basic the constructs, If Else statements and the Select Case statements are at the programmers disposal in helping to make a decision. Here then are the similarities and differences explained with examples of code for both.
Similarities.
Both the statements are used in making a choice in the script between a given set of choices available.
The statements both give a result or a response based on the condition that has been met and gives a different result if otherwise.
They both use data set provided to aid in deciding the code to be processed after completion of the one that had been executing.
Differences.
If Else statement is used for Boolean conditions that is only one of the conditions is allowed whereas Select Case statement is used for conditions that increase according to the value of expressions used.
If Else statement gives it result after a double step navigation while the Select Case statement provide an outcome after going through the cases available before the one that matches the statement.
In Visual Basic .NET the statements differ in syntax as follows.
If Else statement. The syntax for the If Else statement is as shown below
If (condition) Then
Instruction
Else
Instruction
End If
After the If keyword a condition exists that if met the code executes the instruction after Then keyword. If the condition is not met the code executes the instruction after the Else keyword.
Select Case Statement: The syntax for Select Case statement appears as shown below.
Select Case
Case
Instructions
Case
Instructions
Case
Instructions
End Select
The variable value indicated after the Select Case statement goes through comparison with value 1, value 2 and value 3. If it satisfies the value, then it executes the code below the given value.
Examples.
If Else Statement: this example prompts the user to input any number, then display a message “the number input is positive” if the number is greater than zero and displays the message “Input not positive” if otherwise.
Sub Main()
Console.Write(“Please input any number: ”)
Dim number As Integer = Console.ReadLine
If number > 0 Then
Console.WriteLine(“the number input is positive”)
Else
Console.WriteLine(Input is not positive”)
End If
Console.ReadLine()
End Sub
Select Case Statement: this example prompts the users for their choice in colors from a list and displays their choice with a corresponding message on screen.
Sub Main()
Console.WriteLine(“Choose from the following colors”)
Console.WriteLine(“ (i) red”)
Console.WriteLine(“ (ii) blue”)
Console.Write(“Your Choice: ”)
Dim colour As Char = Console.ReadKey.KeyChar
Select Case co...
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

Other Topics:

  • Problems Affecting Uber Technology: Smoothness Of The Application
    Description: Uber technology Inc. is a global transportation service that provides credible and accountable transport facilities to the pedestrians....
    3 pages/≈825 words| 2 Sources | MLA | IT & Computer Science | Essay |
  • Potential Aviation Cybersecurity Threats Research
    Description: Air Traffic Control and airlines are engaging in to help develop policies that would try to catch up with advancing technologies....
    5 pages/≈1375 words| 5 Sources | MLA | IT & Computer Science | Essay |
  • User Interfaces for Visually Impaired People
    Description: Certain aspects associated with spoken language dialogue systems and user interfaces created for blind people are provided within the essay...
    7 pages/≈1925 words| 15 Sources | MLA | IT & Computer Science | Essay |
Need a Custom Essay Written?
First time 15% Discount!