Goto

From Microduino Wiki
Jump to: navigation, search
  • goto

Program will start to run from the existing marked points in the program.

  • Syntax

label:
goto label;    //start to run from label
  • Note

Don’t use goto to program in C. Some programmer think goto statement is never essential, however, if it is used well, specified program can be simplified. Many programmer don’t agree to use goto, because a program is easily to be created through using goto statement excessively, but it will have uncertain running processes, so it can’t be debugged.

Indeed in some instances, goto can come in handy to simplify code, for example, under certain condition if statement can be used to jump out from highly embedded for loop.

  • Example

for(byte r = 0; r < 255; r++){
  for(byte g = 255; g > -1; g--){
    for(byte b = 0; b < 255; b++){
      if (analogRead(0) > 250){ 
        goto bailout;
      }
      //more statement ...
    }
  }
}
bailout:

[Return to Arduino Syntax Manual]