hts.StevenWood.com

[ Last Page ]

Boolean expressions

Boolean expression can have only two possible values,
true or false.

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:

Symbol Meaning
== equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to

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

x = true; then
y= !x; means that y = false ( "not" true);

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.

 
[Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+