Conditional Operators
Submitted by joken on Wednesday, October 23, 2013 - 08:47.
In Visual Basic, we are using Conditional Operators to evaluate a condition that applied to one or two boolean expressions. An expression returning a value if the that expression is true and a different one if the expression is evaluated as false. The logical AND and OR operators both take two operands. Each operand is a boolean expression. It evaluates to either true or false.
The && (logical AND) operator indicates whether both operands are true then it returns true, otherwise it returns false.
Evaluating of Logical AND operators through expressions.
The || (logical OR) operator indicates whether either operand is true, it returns true.
Evaluating of Logical OR operators through expressions.
Expression Results 1 && 1 True or 1 1 && 0 False or 0 0 && 1 False or 0 0 && 0 False or 0Visual Basic Code:
- 'declare a variable
- Dim username As String
- Dim password As String
- 'assign value to a variable
- username = "joken"
- password = "12345"
- 'test if the two expression match, then it welcome the user
- If username = "joken" And password = "12345" Then
- 'returns true
- Else
- 'return false
- End If
Expression Results 1 && 1 True or 1 1 && 0 True or 1 0 && 1 True or 1 0 && 0 False or 0Visual Basic Code: In above example example is applicable in real-world application, especially when you are doing the login- logout system or any other application that need to passed through conditional operations.
Add new comment
- 187 views