Basically, decisions in EZ Math Movie work this way:
You need to decide whether to do a certain job, maybe print
something, or not.
So you write a Boolean statement that captures the decision you need to
The computer evaluates the Boolean statement using current values in the program.
If the Boolean statement is true, then the computer preforms the
actions for the job.
All this happens in an if statement,
If it is true, then....
Here is a diagram that shows the steps outlined in the previous section.
This is the basic flow of an if statement:
Let's look at a few simple descriptions that model this process. A sample
Boolean statement is shown for each.
If a person's score is great enough to win a game, then announce
that the game has been won.
Boolean statement: (score > 100). Is it
If someone is about to take the square root of a negative number,
then issue an error.
Boolean statement: (x < 0). Is it true or
If the temperature is greater than 32 degrees Fahrenheit, then state
that the ice is melting.
Boolean statement: (temp > 32). Is it
If statement syntax
So how does one do this in EZ Math Movie? The keyword if is used. Below is code that checks if x is equal to 2. If it is, it prints the text 'It is true.'
Note the parentheses around the Boolean statement and the curly brackets. They
are all absolutely necessary.
The if statement details
The if keyword is part of a few lines of code that are named an
'if statement'. If
statements work this way:
At the start of a code line state the if keyword.
Follow if with an open parenthesis.
Next, write the Boolean statement that captures the decision that
you want to make.
After the Boolean statement place a close parenthesis.
After that, often alone on the next line, type an open curly bracket.
After the open curly bracket, type the program line(s) that describe
what you want done if the Boolean statement is true.
Finish everything with a close curly bracket, usually on its own
There is no final semicolon.
Running the example program
The example program sets the variables a and b to some initial values.
It then checks if the value of a is less than the value of
The program prints a message if this is true.