Table of Contents## Conditional Statements

Entire Site

Ordinarily, your program statements are carried out in the order
in which they appear. Sometimes you may want to do different
calculations depending upon some condition. You use the `if`

statement to do this. Here’s a calculation
for wages that depends upon the number of hours worked. We presume that
all the `var`

statements have been set
up appropriately.

if (hours <= 40){ pay = hours * rate;`[1]`

} else`[2]`

{ pay = 40 * rate + (hours - 40) * rate * 1.5;`[3]`

}`[4]`

** [1]** The expression in the
parentheses is called the condition. It always asks a yes-or-no
question. In this case, the question is “is the value of the

`hours`

variable less than or equal to 40?”
Other comparison operations are less than (<), greater than (>)
greater than or equal (>=), exactly equal (==), and not equal (!=).
Note that asking if two things are equal to each other requires two
equal signs, not one!