|
|
Boolean expressionsBoolean expression can have only two possible values, A Boolean expression may be a single Boolean variable or consist of a comparison. A simple comparison comparison has the form: expression comparison operator expression The comparison operators are:
You can indicate the opposite by using the exclamation mark (!) in front of the boolean value. The ! mean "not". e.g.
if you have two boolean variables x and y and Boolean variables, or comparisons can be combined using the boolean or logical operators && for and, and || for or. If two boolean expressions are combined using the operator && then both must be true before the compound expression is true. If they are combined using the || operator then at least one of the two must be true before the compound expression is true. The Boolean logic is shown here. Here is a Boolean expression which will test whether an exam mark submitted is a number between 0 and 100: ( 0 <= mark ) && ( mark <= 100 ) The value is true if mark is in this range. |
| ||||