CodeSports

6.1-Predict-Run

Instructions

  • Look at each example , study it carefully.
  • Write a prediction of what it will do when it runs. Your prediction should be added to the code as comments. You should use the key terms subroutine, call and parameter in your predictions.
  • Run the code, compare what happens to your prediction.
  • Add comments to note down and differences between your prediction and what actually happened.

Definitions

  • Subroutines: A subroutine is just a ‘package’ for code. You can write any code inside a subroutine, including calling other subroutines
  • Functions: A subroutine can also return a result (data) to the main program as its final action. This type of subroutine is called a **function.
  • Arguments in a subroutine: As well as getting data out of subroutines, we can put data in. We do this using arguments. You can think of arguments as variables used by the subroutine. They are named in the brackets after the subroutine name when the subroutine is defined and separated by commas.

Help! My code doesn’t work

Make sure that you check for the following things:

  • The subroutine name is identical everywhere it is used (capitals matter)
  • The subroutine call is not indented inside the subroutine
  • The subroutine is defined before it has been called

Hints