# EZ Math Movie, Tutorials, Decisions, If Statement

### Decide with a Boolean.

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 make.
• 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:

### Examples

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 true or false?
• 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 false?
• If the temperature is greater than 32 degrees Fahrenheit, then state that the ice is melting.
• Boolean statement: (temp > 32). Is it true or false?

### 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 line.
• 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 b. The program prints a message if this is true.

### The example program

0ptions
Angle measurement: Degrees Radians

Go on input

Bounds:
Sorry, apparently this browser does not support HTML 5 canvas tag graphics.
Printer

Edit: Runtime          View: Starter Suggestion

To runtime:

Storage:

Editor width: Normal Wide

### And....

Next tutorial: The if with else statement

Here is a link to a related article at EZ Programing Demos:

### Other sites you may find interesting

Like Math and Physics?

Zona Land Education offers explanations, diagrams, and animations on these topics.
And it is all presented in a clear and casual manner.

Here is the link: zonalandeducation.com

Want to learn about programing computers?

EZ Programing Demos has an animated, slow motion, interactive programing language demonstrator.
The site presents basic ideas at a beginner's level.

Here is the link: ezprogramingdemos.com

Custom Search

Name:
Domain:

Name
0

Name:
Name
0