Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about optimizing code

Author: Andrew Dados

Date: 12:06:48 07/08/03

Go up one level in this thread


On July 07, 2003 at 17:18:20, Uri Blass wrote:

>On July 07, 2003 at 16:41:03, Russell Reagan wrote:
>
>>On July 07, 2003 at 16:21:45, Uri Blass wrote:
>>
>>>I almost do not use goto in my program and I learned that I should not do it.
>>
>>goto is not bad always. A long time ago people didn't know the correct way to
>>use goto, and they used it in a lot of wrong ways, so everyone started saying,
>>"don't use goto! goto is bad!" and that made people think that it was bad. It is
>>only bad if you don't know when to use it. It is ok to use it to jump out of a
>>nested loop, for instance.
>>
>>for (x = 0; x < 8; x++) {
>>    for (y = 0; y < 8; y++) {
>>        if (some_condition())
>>            goto done;
>>    }
>>}
>>done:
>>
>>In this case, you want to get out of BOTH loops, so you can't just use a
>>'break'. You could create extra variables and add more if statements to
>>accomplish the same thing, but a goto works best in this situation, and it's
>>okay to use it here
>
>I think that my code do it without goto
>In your example there are also simple alternatives without goto.
>
>for (x=0;x<8;x++){
>  for (y=0;y<8;y++){
>    if (some_condition())
>    {
>      x=8;
>      y=8;
>    }
>  }
>}
>
>
>Another possibility is to define xy=8*x+y and to do
>xy=0;
>while (xy<64)
>{
> x=xy>>3;
> y=xy&7;
> if somecondition()
>   xy=64;
> else
>   xy++;
>}
>
>Note that I added
>x=xy>>3; and y=xy&7 only for simplicty and it may be faster not to have these
>varaibles and to change the condition to calculate them based on x and y when
>you need it.
>
>Uri

Hello Uri. Everyone is entitled to his own oppinion and I think 'evil of goto'
is another programming legend and on many occasions well used goto simplifies
loop design. Of course if you use goto every 10 lines then you are writing in
BASIC :)

 Now think about 'break' statement: it is 'labelless goto' in fact; I have
trouble reading code full of breaks when I need to count brackets; if I see goto
I see where it gets to clearly. Did you see any article about evils of break
statement?

-Andrew-



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.