Visual Basic Questions and Answers – Single-Alternative and Dual-Alternative Selection Structures

«
»

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Single-Alternative and Dual-Alternative Selection Structures”.

1. In Visual Basic __________ is used for coding single-alternative and dual-alternative selection structures.
a) If…Then…Else statement
b) Switch-Case block
c) Recursion
d) function overloading
View Answer

Answer: a
Explanation: In Visual Basic If…Then…Else statement is used for coding single-alternative and dual-alternative selection structures. The If…Then…Else statement statements provide for a statement block where the condition may be true and another if the condition is false.
advertisement

2. The __________ keyword is necessary only in a dual-alternative selection structure.
a) Alternative
b) Next
c) Dual
d) Else
View Answer

Answer: d
Explanation: The Else keyword is necessary in dual-alternative selection structure. The Else part of the If…Then…Else statement evaluates the condition where the condition is false. So, it is the second alternative in the dual-alternativeselection structure.

3. The condition must be a __________ expression.
a) Integer
b) Double
c) Boolean
d) Short
View Answer

Answer: c
Explanation: the condition of If…Then…Else statement has to be a Boolean. The condition of the If…Then…Else statements evaluate to either True or False and depending on that the respective block of code is executed.

4. The set of statements contained in each path is referred to as a __________
a) Condition block
b) Statement block
c) Path block
d) IfElse block
View Answer

Answer: b
Explanation: The code blocks under the If…Then…Else statements are called statement block. One executes if the condition is true and the other if it is false.

5. What is wrong with the following if-else structure?

advertisement
If intQuantity > 5 Then
   dblDiscountRate = .1
Else
   dblDiscountRate = .05
End If

a) No error
b) Conditions not in brackets
c) No ; after statements
d) ‘Then’ should have been ‘then’
View Answer

Answer: a
Explanation: The syntax of the If…Then…Else statement block is,

If condition Then
statement block to be processed when the condition is true
Else
statement block to be processed when the condition is false
End If

6. Comparison operators are also termed as __________
a) Comparators
b) Comparables
c) Relations
d) Relational operators
View Answer

Answer: d
Explanation: Comparison operators evaluate the equality or difference in degree of two given values. This means they tell us how one value is related to another, i.e. if one value is greater or not to another value.
advertisement

7. What is the comparison operator to find if two values are equal?
a) equalsto
b) =
c) EqualsTo
d) Equals
View Answer

Answer: b
Explanation:Comparison operators evaluate the equality or difference in degree of two given values. The = operator tells if one value is equal to another.

8. What is the result of the expression 10-5>3*4-2?
a) Syntax error
b) No resulting value found
c) False
d) True
View Answer

Answer: c
Explanation: Comparison operators are evaluated after any arithmetic expressions. Thus the first sub-condition is not greater than the second, thus it will return false.

9. What is the result of the expression 10-2+20>2*14-2?
a) Syntax error
b) No resulting value found
c) False
d) True
View Answer

Answer: d
Explanation: Comparison operators are evaluated after any arithmetic expressions. In the above syntax, the first expression is greater than second, thus it returns true.

10. What is the result of the expression 10-2+20 ><2*25-2?
a) Syntax error
b) No resulting value found
c) False
d) True
View Answer

Answer: a
Explanation: Comparison operators are evaluated after any arithmetic expressions. Here >< is not any sort of operator. Thus we will get a syntax error, when we evaluate the above expression.
advertisement

Sanfoundry Global Education & Learning Series – Visual Basic.

To practice all areas of Visual Basic, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn