Sunday, June 21, 2020

Compare And Contrast If Else And Select Case In Visual Basic - 550 Words

Compare And Contrast: If Else And Select Case In Visual Basic (Essay Sample) Content: Your NameInstructor NameCourse NumberDateCOMPARE AND CONTRAST: IF ELSE AND SELECT CASE IN VISUAL BASICIn 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 n avigation 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 belowIf (condition) ThenInstructionElseInstructionEnd IfAfter 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 InstructionsCase InstructionsCase InstructionsEnd SelectThe 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 po sitive 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.ReadLineIf number 0 ThenConsole.WriteLine(the number input is positive)ElseConsole.WriteLine(Input is not positive)End IfConsole.ReadLine()End SubSelect 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.KeyCharSelect Case co...

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.