pascal "in statement" equivalent?

Previous topic - Next topic

baicskillet

Hi, this is sort of a newbie-like question, but I'm trying to learn glbasic by porting a simple pascal program, and the program uses very often the "in" statement, as in "x in [1,2,3,4]".
Is there an equivalent for the in statement in Glbasic, or is there another way to do the same the in statement does?

thank you!

MrTAToad

The easiest way would be to set up an array and then use FOREACH to go through each element.

FutureCow

I read that as being part of a loop (i.e x will equal 1, then 2, then 3, then 4)
If that's the case it's easy

Code (glbasic) Select
local x
for x = 1 to 4
    // do something with x here
   debug "x = "+x
next


As MrTAToad says, you could also use an array. This would be helpful if the numbers weren't sequential (in which case a loop wouldn't help you) - if they were "1,2,3,748" for example
Code (glbasic) Select
dimdata myarray[],1,2,3,748
foreach x in myarray[]
   // do something with x here
   debug "x = "+x
next

baicskillet

Awesome, thank you both for your replies! Hmm, from what I've been looking about the "in" statement from Pascal is that is checks whether the variable before the "in" statement is somewhere in the variable or variables after the "in" statement.  So I suppose a foreach loop that compares the before variable with each element in the array, right? Yeah, the number aren't sequential, and sometimes they are letters and strings instead.  I'll try that foreach loop and let you know!