|
-
July 31st, 2007, 10:27 AM
#1
[RESOLVED] C Help - Multiple goto's in a Function
I'm trying to understand multiple goto's in a function. For the code below, if it goes to Return1 & does the line:
RetVal++; , would it then go back into the loop or would it proceed down to the line: return RetVal; ? Thanks for the help!
Code:
int one_bisect(int type, int l_et)
{
int i;
int line[7];
int RetVal = 0;
if (type == -1)
{
for (i = 0; i < 3 + 1; i++)
if ((line[i] - line[i + 3]) > l_et)
goto Return0;
goto Return1;
}
else
{
for (i = 0; i < 3 + 1; i++)
if ((line[i + 3] - line[i]) > l_et)
goto Return0;
goto Return1;
}
Return1:
RetVal++; //would this go back to the loop or to return RetVal?
Return0:
return RetVal;
}
-
July 31st, 2007, 11:12 AM
#2
Re: C Help - Multiple goto's in a Function
No, it won't "go back into the loop". It will "proceed down to the line: return RetVal;"
PS. I havent't seen so silly written code (with "goto" that are no needed al all!) since 70th of the last century when I did my first steps in Fortran programming!
Neither C nor C++ needs using operator goto. Instead using it is a bad style and makes any code not only bad readable/understandable but also not structured and hard maintainable.
IMHO; operator goto should be removed from any modern language.
Victor Nijegorodov
-
July 31st, 2007, 11:26 AM
#3
Re: C Help - Multiple goto's in a Function
Change your logic a little.
Try this
Code:
int one_bisect(int type, int l_et)
{
int i;
int line[7];
int RetVal = 1;
if (type == -1)
{
for (i = 0; i < 3 + 1; i++)
if ((line[i] - line[i + 3]) > l_et)
{
RetVal = 0;
break;
}
}
else
{
for (i = 0; i < 3 + 1; i++)
if ((line[i + 3] - line[i]) > l_et)
{
RetVal = 0;
break;
}
}
return RetVal;
}
-
July 31st, 2007, 11:31 AM
#4
Re: C Help - Multiple goto's in a Function
 Originally Posted by cvogt61457
Change your logic a little.
Try this
...
This code is much better!
Victor Nijegorodov
-
July 31st, 2007, 12:52 PM
#5
Re: C Help - Multiple goto's in a Function
Oh believe me, I fully agree with your logic This is just pre-existing C code that has been given to me to convert into Java and I wanted to make sure I had the right idea of what was going on. Thanks for the help!
-
August 1st, 2007, 02:41 AM
#6
Re: [RESOLVED] C Help - Multiple goto's in a Function
I believe you, slowcoder! (Frankly, it was my guess this code is not youth!)
Victor Nijegorodov
-
August 1st, 2007, 09:52 AM
#7
Re: [RESOLVED] C Help - Multiple goto's in a Function
One goal to strive for is "readability"
Can you make sense of the code easily?
If the code is difficult to read, then something is probably wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|