If Else Endif

The IF...ELSE...ENDIF construct is the third great building block of computing languages.

At many points in your program, you'll have to check something and then execute different commands depending on the outcome. To check things you use the IF command.

IF Guess%=1

GuessRight:

ELSEIF Guess%=2

GuessClose:

ELSE

GuessWrong:

ENDIF

Hopefully, you should by now be able to make a good guess (no pun intended!) as to what this code is attempting to do.

If the variable Guess% equals 1, then go to a procedure called GuessRight:. If Guess% equals 2, then go to a procedure called GuessClose: If Guess% is anything else, then go to a procedure called GuessWrong:.

Note that one of these options has to be chosen. Using ELSE on its own means that if all the other tests have failed, then do this. It's a safety net in some cases, as the program must go somewhere. The last resort here is to call GuessWrong:.

0 0

Post a comment

  • Receive news updates via email from this site