Problems with "goto"... I"M ONLY USING IT ONCE!!

I’m having problems using “goto”… here’s the pertinent sections of code:

void loop(){

  //serialScroll(10);                                                        // Argument = speed, higher number = slower scrolling
  //Insert manual word display code here
  input_scroll("TEST test TEST"    /*, 10*/);

}

void input_scroll(char* words /*, int SPEED*/){

  for(int i=0; i<sizeof(words); i++){                             // i<sizeof(words) -1 ?
    incomingByte[i] = words[i];                                   // sizeof() = bytes = # of chars
    Serial.print(incomingByte[i]);
  }

  goto JUMP_SPOT;                                                      // Located at the beginning of serial_scroll()
  delay(1);
}


void serialScroll(int SPEED){                                 // (eventually) fills up 'patterns[][]' with word/sentence received

  if(Serial.available() > 0){                                            // send data only when you receive data:

    delay(100);

    incomingByte[array_turn] = Serial.read();              // 'array_turn' is used to seperate diff. types of chars.

    array_turn++;

  }

  else{                                                                // Once 'incomingByte[]' is full (everything is read in)

JUMP_SPOT:

    if(array_turn != 0){ 

...

Error message:

LED_Matrix_Driver_Modified.cpp: In function 'void input_scroll(char*)':
LED_Matrix_Driver_Modified:146: error: label 'JUMP_SPOT' used but not defined

The error is referring to the “goto JUMP_SPOT”… help!
(Let me know if you need the full code)

You can't use 'goto' to jump from one function to another. 'goto' can only be used to jump within the same function. Better not use it at all unless you have a really good reason (like error handling).

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

Is there any way to get to another part of a different function?

There is (setjmp/longjmp) but chances are 99.99% that it's the wrong solution to your problem. If there's a piece of code that you need to call from 2 functions, make that piece of code its own function and call it as necessary.

-- The Quick Shield: breakout all 28 pins to quick-connect terminals

try this

void input_scroll(char* words /*, int SPEED*/){

  for(int i=0; i<sizeof(words); i++){                             // i<sizeof(words) -1 ?
    incomingByte[i] = words[i];                                   // sizeof() = bytes = # of chars
    Serial.print(incomingByte[i]);
  }

  Serial.flush();  //flush the buffer so that you end up in the else case
  serial_scroll( 1 ); //not sure what to pass for speed...
  delay(1);
}

Is there any way to get to another part of a different function?

YOU! YES YOU - THERE!

...who told you about the statement that mustn't be named...?!

...that is for adepts only!

/I'll have to talk to the brotherhood about this one...someone is leaking our secrets...we'll find the mole...we have our ways...

Oh boy! It's Prince Spaghetti Day! (might be you need to be from USA to get that one)

If you need a goto, there's a better way, always. Take that from the king of pasta coding, most of my applications came with a side of marinara and garlic bread... oh so many bad habits that developed from BASIC letting you be cavalier about just about everything....

Oh boy! It's Prince Spaghetti Day! (might be you need to be from USA to get that one)

If you need a goto, there's a better way, always. Take that from the king of pasta coding, most of my applications came with a side of marinara and garlic bread... oh so many bad habits that developed from BASIC letting you be cavalier about just about everything....

Woohoo! Another "spagetti code" hen just got knocked off its perch! Nothing wrong code wise about using goto other than it totally confuses those that can't follow code flow logic. Posting code containing a goto in this forum is like tossing rocks on the top of a tin roof hen house. :)

Posting code containing a goto in this forum is like tossing rocks on the top of a tin roof hen house

Jeez, this place is worse than the BBC for repeats.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285802307/15

totally confuses those that can't follow code flow logic

That's assuming there was some logic to understand in the first place.

That's assuming there was some logic to understand in the first place.

So what is your logic connection between bad code and using goto? Got two hens skittering about now! :)

No connection - it's just that in the last ten years, I've seen probably a dozen gotos.

Two or three were in Linux kernel code deep in filesystems and SCSI and Fibre Channel drivers, and all were well documented and justified.

The rest were here, and were neither. :-*

Take that from the king of pasta coding, most of my applications came with a side of marinara and garlic bread... oh so many bad habits that developed from BASIC letting you be cavalier about just about everything....

Just prior to leaving high school and moving out to Phoenix in 1991, I had started to seriously work on code structuring in my BASIC code. At the time, I was mostly using MSBASIC on my TRS-80 Color Computer 3 (ie, Disk Extended Color BASIC - mostly based on early Microsoft BASIC), and was starting to dabble with QuickBASIC 4.5 on a DOS laptop (ok, "luggable") my parents had bought me for tech school when I moved.

I still had some GOTOs, but I was starting to learn functional programming in QuickBASIC, and had already played a lot with structured GOSUBs on the Color Computer...

When I later landed a coding job at a small mom-n-pop shop in Phoenix, I was introduced to "real" structured programming, and I had to learn new habits and break old ones.

All I know is now, looking at my old code on my Color Computer is like looking at a foreign language (Italian?), almost...

;D

...and all were well documented and justified. The rest were here, and were neither.

If you have to have justification and documentation for correct code, that must be a personal preference.

If you have to have justification and documentation for correct code, that must be a personal preference.

No, I'm happy with code I can see to be correct. Sometimes the less experienced have to have the obvious illuminated, as a warning. A bit like the signs on barbed wire, saying "Barbed Wire".