Exercise 4: Writing procedures

Writing procedures

Let's formalize a little: the action of creating a new procedure is known as definition or declaration, and that leads us to introduce new syntactic elements (meaning, things that we can write in our program):

  • the reserved word procedure, indicates that we will define a new element;
  • a name which represents what our procedure will do, which must always start with capital letters. Something important: the brackets of the end are necessary, we will see why later on;
  • a code block, which will be what is executed every time we invoke our procedure. This block starts with an opening brace ({) and ends with closing one (}), similar to what we already did for the program.

Let's see if you got it: write a procedure Drop3Red which drops 3 red stones and a program which uses it.

Give me a hint!

Don't you remember how to write a procedure? Don't worry! It's fine! We are just getting started.

You must sign in before submitting your solutions

Oops, your solution didn't work

  • Check that your program does not have recursion or an infinite loop
  • Check that you have an internet connection
  • Wait a while and try again

We are processing you solution

Please press F5 if results are not displayed after a few seconds