Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: improper access of iterators
Home

[Freeciv-Dev] Re: improper access of iterators

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: Jason Dorje Short <jshort@xxxxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: improper access of iterators
From: Gaute B Strokkenes <gs234@xxxxxxxxx>
Date: Tue, 28 Aug 2001 01:32:13 +0200

On Mon, 27 Aug 2001, hawk@xxxxxxxxxxxxxxxxxxxxxxx wrote:
> On Sun, Aug 26, 2001 at 07:08:01PM -0400, Jason Dorje Short wrote:
>> Raimar Falke wrote:
>> > 
>> > On Sun, Aug 26, 2001 at 05:40:42PM -0400, Justin Moore wrote:
>> 
>> > for(;;) {
>> >   int changed=0;
>> >   unit_list_iterate(pcity->units_supported, punit)
>> >     if (some_condition) {
>> >        handle_unit_disband_safe(pplayer, &pack);
>> >        city_refresh(pcity);
>> >        ai_fix_unhappy(pcity);
>> >        changed=1;
>> >        break;
>> >      }
>> >   unit_list_iterate_end;
>> >   if(changed) break;
>> > }
>> > 
>> > This looks save to me but is a bit ugly.
>> 
>> The same can be accomplished with a single GOTO:
>> 
>> start_over:
>>   unit_list_iterate(pcity->units_supported, punit)
>>     if (some_condition) {
>>        handle_unit_disband_safe(pplayer, &pack, &myiter);
>>        city_refresh(pcity);
>>        ai_fix_unhappy(pcity);
>>        goto start_over; /* use of goto saves ugly loop */
>>      }
>>   unit_list_iterate_end;
> 
> Nice.

Particularly since it's not always clear which iterator macros you can
break; away from and not...we should document this.

-- 
Big Gaute                               http://www.srcf.ucam.org/~gs234/
I have a very good DENTAL PLAN.  Thank you.


[Prev in Thread] Current Thread [Next in Thread]