Or

From BR Wiki
(Redirected from OR)
Jump to navigation Jump to search

Or is a logical operator which evaluates a combination of two logical conditions.

Suppose we wish to ensure that either or both of two conditions are true before we choose a certain path of execution. In this case, we use the OR operator, as in the following application segment:

00010 if semesterAverage >= 90 OR finalExam >= 90 then print "Student grade is A"

This statement contains two simple conditions. The condition semesterAverage >= 90 is evaluated to determine whether the student deserves an A in the course because of a solid performance throughout the semester. The condition finalExam >= 90 is evaluated to determine whether the student deserves an A in the course because of an outstanding performance on the final exam. The if statement then considers the combined condition

semesterAverage >= 90 OR finalExam >= 90

and awards the student an A if either or both of the simple conditions are true. The only time the message "Student grade is A" is not displayed is when both of the simple conditions are false.

Below is a truth table for operator OR.


Operator AND has a higher precedence than operator OR. Both operators associate from left to right.