## FANDOM

2,307 Pages

The If command is used to make choices. If true then do this, else do that. There are several different forms of the if command. It mainly depends on how many things you want to do. Suppose there is a variable myVar that changes value several different places in your program. Then at one point in your program, you need to know if the value is 32. There are two forms of the if command that will do this, for example:

```if myVar = 32 then answer "Variable myVar is 32 now!"  -- checks for 32 then answer
```
```if myVar = 75 then                         -- check for 75
hisVar = myVar - 15                      -- hisVar = 60
end if                                     -- end the if command
```

Both forms of the if command above will work. The top form will only work if one thing is to be done (in this case the answer statement). If there are several statements to executed, the lower form must be used. Those several statements would be inserted before the end if. For example:

```if myVar = 12 then                        -- check for 12
put 15 into myVar                       -- myVar = 15
put myVar+43 into mySum                 -- mySum = 58
end if                                    -- end the if command
```

You can add also use an else option for when the check is not true, look at the following example:

```if myVar = "thirty-five" then                  -- check for "thirty-five"
put 55 into myResistor                       -- myResistor = 55
else                                           -- if not true...
add 81 to myVaristor                         -- myVaristor = 81 more than before
end if                                         -- end the if command
```

You can nest an if command inside another one. This can be done as many levels down as you wish. Suppose the variable myAnimal contains a string naming an animal:

```if myAnimal = "Rat" then                           -- check for "Rat"
put 44 into yourAnimal                           -- yourAnimal = 44
else                                               -- if not true...
if myAnimal = "Eagle" then                       -- check for "Eagle"
put 17 before yourAnimal                       -- yourAnimal = 17 44
else                                             -- if not true...
if myAnimal = "Cow" then                       -- check for "Cow"