Skip to content

Flow Control

LucasMW edited this page Dec 8, 2017 · 5 revisions

Flow Control

if clause:

if(condition) {
  //do something if condition is true
}

if else clause:

if(condition) {
 //do something
}
else {
 //do something else
}

while clause:

while(condition) {
 //do something
}

for clause:

for(exp; condition; expIncrement) {
 //do something
}

while and for are used to make loops. an example:

 //counting until overflow
 byte b;
 for(b=1;b;b++) {
   @b;@"\n";
 } 

Note that the code above its equivalent to this

byte b;
b=1;
while(b) {
 @b;@"\n";
 b++;
}

Note that if command

b++ 

is removed,

the loop would be stuck because b would always result 1,

thus resulting into an infinite loop.

Clone this wiki locally