Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Table of Contents |
---|
Return
The return
statement terminates the execution of a function and returns a value to the calling function.
Code Block | ||||
---|---|---|---|---|
| ||||
string getGreeting(string name) { return Strings:concat("Hello, ", name); } |
Conditionals
if
statement
Code Block | ||||
---|---|---|---|---|
| ||||
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
Code Block |
---|
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
Code Block |
---|
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
Excerpt | ||
---|---|---|
| ||
return | if/else | for loop | foreach |