Exercise 9: Procedures with small holes

Procedures with small holes

What if I want to do a red square now? Or a green one? Do I have to write everything again? Of course not!

Programming is about automating repetitive tasks!

Let's start with something easy: suppose we want to generalize the procedure Drop3Green, in order for it to work with any color we wish (but only one at the time). What we need is to add the procedure a kind of hole

procedure Drop3(color) {
  Drop(color)
  Drop(color)
  Drop(color)
}

…that can later be completed any time it is used:

program {
  Drop3(Black)
  Drop3(Red)
}

Write the previous codes in the editor and check what happens.

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