If so is there any way you could skip from one bit of code to another?
I wanted to jump back to a point in a while loop from a function that is called from within the loop:
Code:
while
{
...
...
label:
...
...
function;
}
function()
{
...
...
goto label;
}
Obvoiusly this does not work, is there a way of doing this??
Thanks.
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Thu May 19, 2005 8:26 pm
Here are some examples of doing it by normal methods:
// This method uses a goto statement.
Code:
void main()
{
char c;
while
{
c = 0x55;
label:
result = function();
if(result == ERROR_CODE_5)
goto label;
}
//==================
function()
{
return(ERROR_CODE_5);
}
This method uses an inner while() loop and the continue statement.
Code:
void main()
{
char c;
while
{
c = 0x55;
while(1)
{
result = function();
if(result == ERROR_CODE_5)
continue; // Go to the start of the inner while() loop
}
}
//----------------
function()
{
return(ERROR_CODE_5);
}
Chubbs
Joined: 02 May 2005 Posts: 14
Posted: Thu May 19, 2005 11:18 pm
Thanks once again, I was able to successfully use it in my program.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum