GLBasic forum

Main forum => GLBasic - en => Topic started by: Richard Rae on 2007-Jul-24

Title: using foreach with multidimensional arrays
Post by: Richard Rae on 2007-Jul-24
Another question:)

Can the foreach command be used on a multidimensional array.I have tried using the following code but it only shows one line

// Project: alpha
// Start: Sunday, July 22, 2007
// IDE Version: 4.237



   
   LOADSPRITE "red.png", 1



   
   LOADSPRITE "green.png", 2


   
   LOADBMP "background.png"



   TYPE ball
   x
   y
   colour

   ENDTYPE

GLOBAL balls[] AS ball
 DIM  balls[9][9]

   FOR y=0 TO 8
   FOR x=0 TO 8

       balls       balls      balls      NEXT
      NEXT




WHILE TRUE


ALPHAMODE -1

foreach item in balls[]
      xx=item.x
      yy=item.y
      col=item.colour
     
      sprite col,xx,yy
next
   
   
   

SHOWSCREEN


WEND
Title: using foreach with multidimensional arrays
Post by: Kitty Hello on 2007-Jul-25
No. It only acts on the first array index. Multidimensional arrays will return the first item
Title: using foreach with multidimensional arrays
Post by: Richard Rae on 2007-Jul-25
No problem Gernot.I will just use a nested for next loop instead.Thanks for the quick reply.