General
Purpose Packages
Automated
Systems
Commercial Data
Processing
Computer Systems
Hardware
Computer Systems
Software
Programming Course
Arrangements

Making Choices with the IF Command

 

Play this video
Using the IF Command! Go Full Screen to see in greater detail?

Introducing the IF Command

Often in programming, a decision will have to be taken depending on things such as the answer a user gives to a question. For example, if the traffic lights are green, then you can cross the road. Otherwise, you should wait to cross.

The IF command is used in such cases. This works just as you may well have seen when working with a formula in a spreadsheet or a computed field in a database.

 

 

 

What you have to do!

  1. Watch Movie 13 which shows how the IF Command can be used to make decisions.
  2. Click the button to download the program folder Traffic_lights. Make sure you choose
    Download Traffic Lights
    Save
  3. Move the folder into your VB Programs folder in Documents. Right click and choose Extract All or Extract Files. Click OK or Next and keep going until the process is Finished. .
  4. Create the subroutine display_results as shown in the movie.
  5. Tick off your Progress Grids.

 

 

 

Using the Else Command (With a little bit of the OR operator too)

Play this video
IF THEN ELSE - another way to make a decision! Go Full Screen to see in greater detail?

The problem above uses 3 IF commands that will all be tested by the computer.

Here we consider how the use of the Else command can mean that only one conditions may have to be tested by the computer, helping to speed up how quickly a program runs.

Oh! By the way, see if you can spot the deliberate mistake. What should it be?

 

 

 

 

What you have to do!

  1. Watch Movie 14 which shows how to change the program code to make a decision depending in the result of something else (Using Else with an IF)
  2. Change the display_results for the Traffic_lights program as shown.
  3. Tick off your Progress Grids

 

Mark off Exercise 10 in your progress grids.

 

What you should now be able to do!

 

Continue to Exercise 11: Programming Designs

 


 

 

 

 

Home | S1 Topics | S2 Topics
Computing Standard Grade | Info Systems Intermediate II | Info Systems Higher | Internet Safety
Log into Glow | School Website | Contact Us