Acknowledgement: This text is a formatted version of a message posted to *Teaching on WorldMOO by Andy Bakun.
MOO programs are made up of statements. All statements end in a semicolon. Statements also can include other statements, in the body of a MOO command.
that's one statement
for x in [1..10]
y = y + x;
This is a statement within a statement. The for loop is a statement, and the 'body' of the for loop contains a statement.
This is also a nested statement, one statement in a the body of the fork, and the fork counts as a statement.
Statements are made up of commands or expressions. Commands tell the moo to do something. Commands do not return values. Commands can't be nested (but statements can). Commands can take expressions as arguments, but commands can't be used as arguments. Expressions return a value. Expressions can take arguements, and expressions can be nested (expressions within expressions)
The moo commands include: while, for, if, return.
An expressions is anything that returns a value: all the builtin functions, any MOO value, any operations on those values.
Examples of statements are:
this evaluates the expression 0, and then throws the result away.
this evaluates 1+2, and throws the result away.
foo = 1+2;
This is made up of two expressions, 1+2 and a variable assignment. foo is a variable name. 1+2 is evaluated, and the result is assigned to the variable foo. foo is evalualated the result is thrown away.
foo = bar = baz = 1;
This is a nested expression, 1 is evaluated, and assigned to baz. baz is evaluated and the result is assigned to bar. bar is evaluated and the result is assigned to foo. foo is evaluated and the result is thrown away.
This is the null statement. It returns 0.
this is a statement made up of a command. the while command takes 1 argument, an expression that returns a number. In this case, the expression is 1, which returns 1. While does not return anything. It's a syntax error to assign the result of any command to anything. x = while (1) is invalid.