back


Using If-Then Statements

One of the most useful features of any computer language is the IF-THEN statement. It allows you to control the computer's response based on certain conditions. Normally, the code in your program is executed in sequence: line-by-line. It makes it possible for you to make the computer do more work with less effort on your part.

If-Then statements use the same kind of logic we use in our own decision making. For example:

IF I'm hungry THEN

  Eat something!
END IF
However, usually we have some alternative in mind if the condition we specify is not true. We use what is called the ELSE statement to go with the If-Then statement. It ends up like this:

IF I'm hungry THEN
   Eat something!

ELSE Do some more situps

END IF

Assignment
  • homework: read pages 108-117 in your Visual Basic Book (Sprague).
  • Do the Cereal problem starting on page 117.