(MAD) Commands and Expressions Lesson

Commands and Expressions

code block for button:
when Button1.Click
do call Sound1.PlayWhen an event handler fires, it executes a sequence of commands in its body. A command is a block that specifies an action to be performed. Most command blocks are purple in color.

A call block command is generated by a procedure (function or method) that has been created. The call block is used to invoke the procedure. As we have learned previously, procedures (functions/methods) have a parameter where we can supply arguments to completely specify information the procedure needs to execute.

when Button1.Click
do
call Sound1 .Play
call Sound1.Vibrate millisecs 500
set Label1 BackgroundColor to {yellow}
set Label1 Text to CS Rocks!

The set command is used to set information.

Notice the blocks have sockets on the right edge of the command for supplying the input values. These inputs can be expressions to denote a particular value or strings.

Expressions

Expressions are found in the math block editor. They can be used for assigning values, creating basic arithmetic expressions with addition, subtraction, multiplication, division and modulus.

code blocks: 
200 + 300
if true
then 500
else 0

min 800
500

1000 / 2

Remember the order of operation when creating expressions.

  • P - Parentheses first
  • E - Evaluate Exponents
  • M - D - M - Multiply, divide, modulus
  • A - S   - Add, subtract
  • Work left to right

We know in programming that Multiplication, Division and Modulus have the same precedent working left to right. So, I've added an acronym M for Modulus.

Please Excuse My Dear Magnificent Aunt Sally

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION