Conditions
Previous  Next

In GCBASIC (and most other programming languages) a condition is a statement that can be either true or false. Conditions are used when the program must make a decision.
A condition is generally given as a value or variable, a relative operator (such as = or >), and another value or variable. Several conditions can be combined to form one condition through the use of logical operators such as AND and OR.

GCBASIC supports these relative operators:
Symbol
Meaning
=
Equal
<>
Not Equal
<
Less Than
>
Greater Than
<=
Less than or equal to
>=
Equal to or greater than

In addition, these logical operators can be used to combine several conditions into one:
Name
Abbreviation
Condition true if
AND
&
both conditions are true
OR
|
at least one condition is true
XOR
#
one condition is true
NOT
!
the condition is not true
NOT is slightly different to the other logical operators, in that it only needs one other condition. Other arithmetic operators may be combined in conditions, to change values before they are compared, for example.

GCBASIC has two built in conditions - TRUE, which is always true, and FALSE, which is always false. These can be used to create infinite loops.

It is also possible to test individual bits in conditions. To do this, specify the bit to test, then 1 or 0 (or ON and OFF respectively). Presently there is no way to combine bit tests with other conditions - NOT, AND, OR and XOR will not work.

Example conditions:
Condition
Comments
Temp = 0
Condition is true if Temp = 0
Sensor <> 0
Condition is true if Sensor is not 0
Reading1 > Reading2
True if Reading1 is more than Reading2
Mode = 1 AND Time > 10
True if Mode is 1 and Time is more than 10
Heat > 5 OR Smoke > 2
True if Heat is more than 5 or Smoke is more than 2
Light >= 10 AND (NOT Time > 7)
True if Light is 10 or more, and Time is 7 or less
Temp.0 ON
True if Temp bit 0 is on
This site hosted for free by:
SourceForge.net Logo