GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2011-12-29 19:45:58

Daniel
Member
Registered: 2011-05-04
Posts: 25

The gQuery foreach loop needs to be nestable

Right, here's the deal.

My gQuery Lib has a foreach loop. I'm trying to have it nestable.

Which one of these seems to be most intuitive or usable/clean?

Expandfor( each( list, 'i' ) as item() )
  for( each( list2, 'j' ) as item() )
    draw_text( 5, 5, i*j )
Expandfor( each( list ) as key_value() )
  for( each( list2 ) as[1] key_value() ) 
    draw_text( 5, 5, value * value[1] )
Expandfor( each( list ) as item() )
  for( each( list2 ) as item() )
    draw_text( 5, 5, value[1] * value )

I'm actually leaning towards number 1, interesting. Its the slowest but simplest as it allows you to define your own iterator name. For the record, the current implementation of the nested foreach uses number 2, which I only prefer because it is backwards compatible with the old style foreach loop.

Offline

#2 2011-12-29 20:00:56

Daniel
Member
Registered: 2011-05-04
Posts: 25

Re: The gQuery foreach loop needs to be nestable

Of course, the reason it doesn't work right now is because the foreach loop stores both values into the "key" and "value" variables which means you can't access the outer-loops key/value's

Offline

Board footer

Powered by FluxBB