For Each Loop

kanaida

Active Member
Licensed User
Longtime User
After my second app, I *really* miss my for each loops...

B4X:
Dim arr(4) as string
For Each x in arr
 'Do something with x directly since it's already the object we wanted.
Next

Example 2: with casting built in
B4X:
Dim arr(4) as object
For Each x as SOME_TYPE in arr
 'Do something with x directly since it's already the object we wanted, of the type SOME_TYPE.
 'I believe this would even make it easier to keep intellisense working properly.
Next

I know is the same as for:
B4X:
For x = 0 to arr.length-1
Dim obj = arr(x)
'Do something with obj
Next

But it's much cleaner though, and saves much typing, typos etc... not to mention that the x variable becomes the object we're getting rather than doing a get(x) with some decralaration...
Most of the time in other vb languages we solely use for each, unless we're grabbing things in the middle which isn't too often for most day to day stuff. It's just one of those little things that we would really use in every project multiple times...
 
Last edited:

CharlesIPTI

Active Member
Licensed User
Longtime User
+ 100

ahh yes indeed

:sign0137: :sign0148: :sign0156:

Actually I'm evaluating inside of loops like this AND unfortunately is usually an Object forced into a tag property just to hold
a name value and maybe some other attributes. That's right ,,, in order to get the 'name' of my label,
so I can update it or whatever...
I have to create an object whose properties ----include a name-----, and I might as well throw some other properties on it since I'm in there already.

Create a bunch of labels to Throw onto a panel --- for each X in list {list of label names}
-- create new label with x-string as name and send it to formatting
method to standardize its text. font , size, whatever
return retVal_label to calling method - again

Next Sub --> evaluate nested label name from tag-->Object.name
and place Via X,Y coordinates by name ..
or adjust label size by name ..

Its tedious .. but yea I'm just whining Sorry
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…