Pinguino Forum
Using "goto" - Printable Version

+- Pinguino Forum (http://forum.pinguino.cc)
+-- Forum: Hardware (http://forum.pinguino.cc/forumdisplay.php?fid=6)
+--- Forum: 32-bit (PIC32MX) Pinguino (http://forum.pinguino.cc/forumdisplay.php?fid=43)
+---- Forum: Bugs & Suggestions (http://forum.pinguino.cc/forumdisplay.php?fid=46)
+---- Thread: Using "goto" (/showthread.php?tid=4980)



Using "goto" - Newcomer - 16-01-2018

Hello !

I have tried using the GOTO command.

However, no matter how I place "end:" it says " error: label at end of compound statement " when compiling.

I have tried the following example (Serial Write Example) on the wiki and the result is the same.

I am using the Olimex Pinguino Micro (32-bit) and Windows 10 with IDE v11.

I have tried it also with v12 on a LINUX-computer (Ubuntu) with the same result.

Any suggestions ?

NB ! I had to correct some parenthesis faults in the example to get rid of some other fault indications.



// test serial with a modified Fonera
// pinguino is connected to the serial port of the Fonera
// jean-pierre MANDON 2008

int i;
int caractere,caractere1,caractere2;

void setup()
{
// led's are on output 0..7
for (i=0;i<8;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}

// Serial is 9600 bauds
Serial.begin(9600);
}

void loop()

{
// if something was received
if (Serial.available)
{
// read received character
caractere=Serial.read();
if (caractere=='W')
{
// wait for the next character
delay(3);

// and try to read if something was received
if (Serial.available)
caractere1=Serial.read();
else
{
// else reset receive buffer
Serial.flush();
//and exit from loop
goto end;
}
delay(3);
if (Serial.available)
caractere2=Serial.read();
else
{
Serial.flush();
goto end;
}
// second and third characters are ASCII so sub 48 decimal
if ((caractere1>=0x30)&&(caractere2>=0x30))
{
caractere1-=0x30;
caractere2-=0x30;
}
else
{ goto end;
// and use those characters to light a led
digitalWrite(caractere1,caractere2);
// say OK to the transmitter
Serial.print("bonjour\n\r");
end: }

}
}
}



Regards,

Urban