Wish Inline Dim

Troberg

Well-Known Member
Licensed User
I very often find myself writing code such as:

B4X:
Dim n as int
For n=0 to 100
  'Do stuff
Next
Now, some languages have a neat construct which saves a mostly unnecessary line. In Basic, it would be something like:

B4X:
For n as int=0 to 100
   'Do stuff
Next
Basically, an inline Dim where the variable is dimmed on first use. Somewhat like an even shorter form of:

B4X:
Dim x as int = 0
as a substitute for:

B4X:
Dim x as int
x=0
Personally, I wouldn't use it on important or complex variables, but for trivial ones like in the example, it's very practical.
 

Jaames

Active Member
Licensed User
You don't need to call dim here at all.
A for loop automatically declares an int value (if it is not already declared).
And it is working like that from the first version I bought 1.8 (year 2012) :)
 
Top