Two new language features in the next version

Erel

B4X founder
Staff member
Licensed User
Longtime User
Basic4android v2.20 will include two new language features that will help with writing "cleaner" code:
- Declaration and assignment in the same line:
B4X:
Dim h As String = "Hello"
'The value expression can be located before or after the type.
'This code is also valid:
Dim i1 = 1, i2 = 2, i3 = 3 As Int

- For Each block. A simpler way to iterate over all values in a collection or array:
B4X:
'Numbers is a List or array.
For Each n As Int In Numbers
 Sum = Sum + n
Next

For Each v As View In Activity
 If v Is Label Then
  Dim lbl As Label = v
  lbl.TextSize = 20
 End If
Next

'Disable several buttons:
For Each b As Button In Array As Button(btn1, btn2, btn3, btn4, btn5)
 b.Enabled = False
Next
 

Smee

Well-Known Member
Licensed User
Longtime User
:sign0188:
Excellent work Erel.

Now for the next big one

With labelName
.colour
.width
. etc .....
End With

:sign0098:
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
:sign0188:
Excellent work Erel.

Now for the next big one

With labelName
.colour
.width
. etc .....
End With

:sign0098:

'With' would be nice, 'Using' (and direct disposing after end using) perhaps even more, memory wise...
 
Upvote 0
Top