How to store Boolean expressions in variables?
Many programming languages let you define a variable as a Boolean data type.
In REALbasic, you can define a variable as a Boolean data type like this:
Dim Guilty As Boolean
In C++, you can define a variable as a Boolean data type like this:
bool Guilty;
Remember You can just stuff a Boolean expression into a variable in Liberty BASIC and Revolution because neither of these languages forces you to declare your variables ahead of time like C++ or REALbasic.
You can then assign a Boolean expression to a variable in the following way:
Guilty = (4 < 54)
This example assigns the value of True to the variable Guilty. The preceding statement tells the computer, “The Boolean expression of (4 < 54) is true. Thus the value of the Guilty variable is True.”
To see how a variable can hold a Boolean value, try the following Liberty BASIC program:
Guilty = (4 < 54)
IF Guilty THEN
PRINT “Slap him on the wrist and let him go.”
END IF
END
Each time that you run the preceding program, it prints the message Slap him on the wrist and let him go.
Here’s what the equivalent program looks like in Revolution:
put 4 < 54 into Guilty
if Guilty then
put “Slap him on the wrist and let him go.” into message
end if
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply