1 / 6

4c – Logical Operations

4c – Logical Operations. CSCI N331 VB .NET Programming. Lingma Acheson. Department of Computer and Information Science, IUPUI. Logical Operators. AndAlso Connects two or more conditions All the conditions have to be true for the compound condition to be true E.g.

keelia
Download Presentation

4c – Logical Operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4c – Logical Operations CSCI N331 VB .NET Programming Lingma Acheson Department of Computer and Information Science, IUPUI

  2. Logical Operators • AndAlso • 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 intFinalScore>= 85 AndAlsostrExtra = “Pass” Then strLetterGrade = “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 strIdentity = “student”AndAlsointIncome < 10000Then intLoanAmount = 25000 Else intLoanAmount = 10000 End If

  3. Logical Operators • OrElse • 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 intFinalScore>= 90 OrElseintProject >= 95 Then strLetterGrade = “A” End If

  4. Logical Operators • Xor • Connects two or more conditions • Exclusive OR:Onlyone 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 intFinalScore< 60 XorintProject < 60 Then strLetterGrade = “D” Else strLetterGrade = “F” End If

  5. Logical Operators • Xor ‘An example determining discount ‘Either a senior citizen or a VIP member can get 10% discount If strStatus = “senior” XorstrMember = “VIP” Then intDiscount = 10 ‘The above If condition will be false if the person is a senior VIP or neither, thus ‘it will false into the below ElseIf branch ElseIfstrMember = “VIP” Then ‘If a senior VIP, will get 20% discount intDiscount = 20 End If

  6. 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 NotstrStatus = “kids” Then ‘ if status is not kids, get 10% intDiscount = 10 ‘ discount Else ‘ If status is kids, get 20% discount intDiscount = 20 End If

More Related