Android Question ternary using tenary

Douglas Farias

Expert
Licensed User
Longtime User
Hi all
what the best way, correct to make this code in b4a?

B4X:
For i = 1 to 31
spdia.Add(i < 10 ? "0".concat(i) : i);
next

i made
B4X:
    For i = 1 To 31
    If i < 10 Then
    spdia.Add(0&i)
    Else
    spdia.Add(i)
    End If
    Next

but have a way to make this with tenary, 1 line?
as Experienced programmers as you simplify this code?
 

sorex

Expert
Licensed User
Longtime User
in case you want it to work with strings aswell you could use

B4X:
For i = 1to31
t="000"&i
spdia.Add( t.SubString(t.Length-3) )
Next

this one would work from 000-999 (didn't try this code tho but I use this method for over a decade in other languages)
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
and logic question

its possible make a major to minor number at for?

B4X:
for i = 2014 to 1990
log(i)
next

its possible make this?
 
Upvote 0
Top