Decide

Purpose

The Decide command is one of those commands that can add smarts to your program. Its purpose is to select which list of commands the program will execute based on some condition(s). It associates lists of commands to test expressions to be used when executed.

The typical use case of this command is that you want to execute a bunch of commands only when some expression is true. So for example if you want the athlete to run an additional mile if he/she has finished the previous run in under 35 minutes then you need to use a Decide command.

Definition

In order to issue a Decide command you have two options, either right-click and select New > Decide or press Space and then D

Decide Definition

After that you will see that it asks you to enter a test expression. When the Decide command runs this expression will be calculated when the and if the result is true (not false or nil) then the commands under that expression will be executed.

By entering a test expression and clicking Save the list of commands under this test expression opens up (you can toggle the commands under a test expression by clicking on the test expression). It is initially empty but you can add as many commands as you want.

Decision Open

You can also add as many decisions (test expression with its commands) as you want on a Decide command. This can be achieved if you right-click and select Add a Decision. Note that if you have more than one decisions they can be rearranged (change the ordering) because, as you will read below, if more than one test expressions result to true the first one (by order) will be chosen.

You can edit or delete (unless there is only one left) a decision if you right-click on it and select Edit or Delete Decision.

Finally there is a decision that cannot be edited or deleted which has an implicit test expression (if none of the other test expressions result to true) which is the ELSE decision. This will run if none of the other decisions is chosen.

Execution

The Decide command execution, although simple, enables one to write really sophisticated programs. It starts by calculating the test expression of the first decision. If the result of the calculation is false or nil then it moves to the second decision, if there is any, and repeats the calculation of the test expression. It will do the above until it finds the first decision that the result of its test expression calculation is true and selects it. If doesn’t find one it selects the ELSE decision. Then executes the list of commands that are associated with the selected decision one by one. After that the program continues with the execution of the commands after the Decide.