Simple If Exercise Answers
Walkthrough the following if statements and indicate the output produced
1. If 5 < 15 Then
Display "1 - True"
End If
The number 5 is less than the number 15.
It will Display 1 - True
2. If "Andy" > "Bob" Then
Display "2 - true"
End If
The character A is NOT greater than the character B.
No output
3. If "bob" < "BOB" Then
Display "3 - true"
End If
All uppercase letters are less than all lowercase letters.
“b” is not < “B”
No output
4. If 15 <= 15 Then
Display "4 - true"
End If
The number 15 is equal to the number 15
It will Display 4 - True
5. If 5 = 15 Then
Display "5 - True"
End If
The number 5 is not equal to the number 15
No output
6. If "Bob" < "Bobby" Then
Display "6 - true"
End If
If two strings are the same until one string ends, the shorter string is less than the longer string
It will Display 6 - True
7. If "bob" <> "BOB" Then
Display "7 - true"
End If
Lowercase b not equal to uppercase B
It will Display 7 - True
8. If "15" <= "fifteen" Then
Display "8 - true"
End If
Comparison is based on character ASCII values.
The character “1” has an ASCII value of 49, the “f” has an ASCII value of 102.
It will Display 8 - True
9. If "A" < 6 Then
Display "9 - true"
End If
Invalid because you cannot compare nonnumeric
data to numeric
Program will die
10. If "6" > 5 Then
Display "10 - true"
End If
Invalid, no error
This should be an error and in most languages would be but VB looks at the nonnumeric constant “6” and recognizes that it is a number. Since 6 is greater than 5
It will Display 10 - True
11. If "Bob" < "" Then
Display "11 - true"
End If
A null string “” or nothing is less than everything.
No output
12. If "" < " " Then
Display "12 - true"
End If
A null string “” or nothing is less than anything including a space which IS something.
It will Display 12 – True
13. If "6" > “!” Then
Display "13 - true"
End If
The character “6” has an ASCII value of 54, the “!” has an ASCII value of 33.
It will Display 13 - True