CSCI N 331 VB NET Programming 4 c
CSCI N 331 VB. NET Programming 4 c – Logical Operations Lingma Acheson Department of Computer and Information Science, IUPUI
Logical Operators • And. Also – Connects two or more conditions – All the conditions have to be true for the compound condition to be true – E. g. ‘Grade will be A if both conditions are satisfied If int. Final. Score >= 85 And. Also str. Extra = “Pass” Then str. Letter. Grade = “A” End If ‘The loan amount will be 25000 if the person is a student And income is lower ‘than 10000. ‘Otherwise (either a student or low income), the amount will be 10000 If str. Identity = “student” And. Also int. Income < 10000 Then int. Loan. Amount = 25000 Else int. Loan. Amount = 10000 End If 2
Logical Operators • Or. Else – Connects two or more conditions – At least one condition has to be true for the compound condition to be true (also true if more than one condition is true). – E. g. ‘Grade will be A if it meets at least one of the conditions. ‘The grade will be A if either the final score is 90+ or the project score is 95+ ‘The score will still be A if both conditions are met. If int. Final. Score >= 90 Or. Else int. Project >= 95 Then str. Letter. Grade = “A” End If 3
Logical Operators • Xor – Connects two or more conditions – Exclusive OR: Only one condition can be true for the compound condition to be true. – E. g. ‘Grade will be D only if it meets one of the conditions. ‘The grade will be D if either the final score is <60 or the project score is < 60 ‘If both are < 60, the grade will be F. If int. Final. Score < 60 Xor int. Project < 60 Then str. Letter. Grade = “D” Else str. Letter. Grade = “F” End If 4
Logical Operators • Xor ‘An example determining discount ‘Either a senior citizen or a VIP member can get 10% discount If str. Status = “senior” Xor str. Member = “VIP” Then int. Discount = 10 ‘The above If condition will be false if the person is a senior VIP or neither, thus ‘it will false into the below Else. If branch Else. If str. Member = “VIP” Then ‘If a senior VIP, will get 20% discount int. Discount = 20 End If 5
Logical Operators • Not – Negate the condition. If the condition evaluates to true, negate the condition will make it false, and vise versa. E. g. If Not str. Status = “kids” Then ‘ if status is not kids, get 10% int. Discount = 10 ‘ discount Else ‘ If status is kids, get 20% discount int. Discount = 20 End If 6
- Slides: 6