Control Structures
- Former user (Deleted)
- Jacques Marais
Owned by Former user (Deleted)
Return
The return
statement terminates the execution of a function and returns a value to the calling function.
string getGreeting(string name) { return Strings:concat("Hello, ", name); }
Conditionals
if
statement
if(name == "Tom") { Mez:log("Hello Tom!"); } else if (name == "Frank") { Mez:log("Hello Frank!"); } else { Mez:log("Hi! Who are you?"); }
Loops
for
loops
for(;;) { // Technically not possible, as iterations // have a limit. Mez:log("Infinite loop!"); } for(int i = 1; i <= 10; i++) { Mez:log(i); } int i = 0; for(; i < 10;) { Mez:log("While style loop!"); }
foreach
loop
SomeObject[] objectCollection = SomeObject:all(); foreach(SomeObject currentObject: objectCollection) { currentObject.description = "Foreach style loop!"; }
Additional Mentions and References
- Control Structures in the Quick Reference
if
used in tutorial Lesson 3for
andforeach
used in tutorial Lesson 10