Вы находитесь на странице: 1из 10

IF Statements

An IF Statement allows you to display a value or make a calculation based on a condition.

For example:

IF x = 1 THEN DISPLAY "x is equal to 1" OTHERWISE DISPLAY "x is not equal to 1".

X 1 Try changing the value in this cell.


TRUE FALSE
=if(C9=1,"x is equal to 1","x is not equal to 1") This is the formula
x is equal to 1 This is the result

IF Statements are structured in the following way.

=IF(CONDITION, Do this if condition is true, Do this if the condition is false)

Nested IF Statements
If you need to check more than one condition then you can use a nested if statement.

For example:

IF (Condition,if(condition,TRUE,FALSE),FALSE) If the condition is true then check another condition


IF (Condition,TRUE,if(condition,TRUE,FALSE)) If the condition is false then check the other condit

X Result X does not equal 1


Y
If X and Y are equal to 1 display "X and Y are equal".
If X isn't equal to 1 display "X is not equal to 1".
If X is equal to 1 but Y isn't display "They are not the same".

Your Go
Using the Command and Ships worksheets, create the battleship game using nested if statements.
lue in this cell.

then check another condition


e then check the other condition
PLAYER 1 BATTLESHIP COMMAND CENTER
This will show all your hits Place X in a cell to fire your missles

RADAR STATION MISSILE GUIDANCE CONTROL SYSTEM

Number of hits << Research the COUNT IF statement


CENTER
to fire your missles

E CONTROL SYSTEM
PLAYER 2 BATTLESHIP COMMAND CENTER
This will show all your hits Place X in a cell to fire your missles

RADAR STATION MISSILE GUIDANCE CONTROL SYSTEM

Number of hits << Research the COUNT IF statement


CENTER
to fire your missles

E CONTROL SYSTEM
BATTLESHIP COMMAND CENTER
Place your ships here
X X X

X X X X

X X X X X

MISSILE GUIDANCE CONTROL SYSTEM


3 Ships

2 Ships

1 Ship
BATTLESHIP COMMAND CENTER
Place your ships here
X X X

X X X X

X X X X X

MISSILE GUIDANCE CONTROL SYSTEM


3 Ships

2 Ships

1 Ship

Вам также может понравиться