Difference between revisions of "Foreach"

59 bytes added ,  18:13, 30 May 2014
entries are 'stringmap' not 'map' artays
imported>Odessa
(Created page)
 
imported>Odessa
(entries are 'stringmap' not 'map' artays)
Line 1: Line 1:
{{Function
{{Function
  |origin = NVSE
  |origin = NVSE
  |summary = Added by NVSE V4. Used to repeat a script block for each entry in an array. Each entry is itself a [[Array Variables|map array]] with two fields, "key" and "value".
  |summary = Added by NVSE V4. Used to repeat a script block for each entry in an array. Each entry is itself a [[Array Variables|stringmap array]] with two fields, "key" and "value".


Within foreach loops, the command 'continue' may be used to skip any remaining loop code for that entry, and move on to the next. In the same context, the command 'break' may be used to end the loop immediately, ignoring any remaining entries.
Within foreach loops, the command 'continue' may be used to skip any remaining loop code for that entry, and move on to the next. In the same context, the command 'break' may be used to end the loop immediately, ignoring any remaining code and entries.


  |name = Foreach
  |name = Foreach
Line 58: Line 58:
     let rMusician := aEntry["value"]
     let rMusician := aEntry["value"]
     if rMusician.GetDead
     if rMusician.GetDead
         continue ; * we ignore dead members
         continue ; * Go direct to next entry: we ignore dead members
     endif
     endif
     rMusician.AddItem Beer 1
     rMusician.AddItem Beer 1
Line 71: Line 71:
     let rMusician := aEntry["value"]
     let rMusician := aEntry["value"]
     if rMusician.GetInWorldSpace Liverpool == 0
     if rMusician.GetInWorldSpace Liverpool == 0
         break ; * If we find a member is not in Liverpool, we give up
         break ; * End Loop immediately if we find a member is not in Liverpool
     endif
     endif
     rMusician.AddItem Beer 1
     rMusician.AddItem Beer 1
loop
loop


; Give a beer to each member of the Beatles until one is found not to be in Liverpool. Hence, assume all Beatles except Paul are in Liverpool; since Paul is the second entry of the array, only John gets a beer.
; Give a beer to each member of the Beatles until one is found not to be in Liverpool- assume that all Beatles except Paul are in Liverpool; since Paul is the second entry of the array, only John, the first, gets a beer.


</pre>
</pre>
Anonymous user