Variable assignment within a loop?

U

unba1300

Guest
This is a simple example of something I'd like to do in order to assign values to variables within a loop. But I can't seem to figure out how to merge varFood & iLoop together to make varFood1, varFood2, etc.

B4X:
Dim iLoop As Int
For iLoop = 1 To 5   
    varFood & iLoop = 'pick a food at random from a list.
Next iLoop

Is this possible, or should I use an array? Thanks.
 

Mahares

Expert
Licensed User
Longtime User
B4X:
Dim varfood(5) As Int
that will allow you to call your variables: varfood(0), varfood(1), varfood(2), varfood(3), varfood(4)

Forgive me if I misunderstood the question.
Mahares
 
Upvote 0
Top