Beginning of dialog window. It congratulates you on completing this exercise. Escape will cancel an close the window.
Congratulations, you've completed this exercise!
Would you like to...
You can always navigate to any page at a later time.
Beginning of dialog window. It asks that code be input before running.
There isn't any code
Type in some code and then press the run button to see what it does
Part 6: Mutate the Bugs
Actions
Actions
Often times inside a program, we want to run the same code sections many times in different places. We usually want to eliminate this duplicate code to save time, reduce errors and make things easier to change.
We do this by writing procedures that we call whenever we want code to run. In Quorum, these are called actions.
You didn't realize it, but we have already been using an action called Main. The computer always starts running our program from our Main action. We haven't had to use it so far, because Quorum automatically puts our code inside a Main action if we don't use any other actions.
Now that we are going to use other actions though, we always need to include it.
Creating Actions: Part 1
In Quorum to create an action, we use the keyword action followed by the name of the action. We usually capitalize the first letter of an action name, but it is not required. Naming rules for actions are the same as variables, it must start with a letter.
Since we are going to have a code block inside the action, we also need to include an end to mark where the action ends.
Try it!
Creating Actions: Part 2
You can put any type of code that you've learned so far inside the Main action or call other actions from it.
We are going to create another action now that we will call from the Main action.
To do this, just create a new action after the end statement of the Main action.
Try it!
Creating Actions: Part 3
At the moment, we have two actions in our program, but no code to run inside the actions. We'll learn how to call an action in a moment, but first, let's write some code inside the PrintMsg action.
To keep our example simple, we are going to write a simple output message to the screen.
Try it!
Calling Actions
Now, in order to complete this program we need to call our PrintMsg action from our Main action so that it will execute.
In Quorum, this is very easy to do, we just insert a line of code in the Main action that redirects the computer to the other action. We do this adding the line PrintMsg() to the Main action.
The parentheses are necessary after the action name to notify the computer that it should run an action.
Try it!
Actions: More Information
Here is our full example:
Actions are an important and useful concept in programming, but we've only covered the basics so far. You can also do things like pass variables to an action and return values from an action.