Imagine a world...

wonder

Expert
Licensed User
...where the first position of an array is 1 and not 0.
B4X:
Dim a(10) as Int

For i = 1 to 10
     label1.text = label1.text & a(i) & crlf
Next
World peace achieved, no more war, hunger or misery on the planet. Humanity is united. Perfect utopia.

Hell yeah!!!! :cool::D
 

lemonisdead

Well-Known Member
Licensed User
Well, I do have a solution for you : remember that your school teacher lied to you !
0 is one and sole
1 is a twin
Should be better and you will be able to buy those companies :D
 

lemonisdead

Well-Known Member
Licensed User
you as a developer should know that as you learn the new language
Damned, I even don't know where I have put the keys of my car ;)
Should I PM a kind IT guy to remember me

But, I wonder why not all languages don't use the ZERO as a base. It spoils the memory :rolleyes:
 

Beja

Expert
Licensed User
It's normal to start from zero.. when you travel you start from mile zero, right? Mile one is one mile away (Duh!)
But,
if you started from mile 1 then you will end your trip 1 mile past your destination and you need to make a U-turn, and you will never
be able to stop at the destination, and will U-turn until tomorrow.
 

WAZUMBi

Well-Known Member
Licensed User
Visual Basic has 'option base 1' to change the default base for arrays (if I remember correctly) from 0 to 1
I once tried to implement OPTION BASE in a program and it confused the hell out of me. It literally gave me nightmares.
Stick with zero....
 

Troberg

Well-Known Member
Licensed User
I don't care either way, althoug, occasionally, it would be nice to be able to set any base, such as:

Dim Year(1900 to 2100) as int

This way, by the way, is how i declare every array in VB, with an explicit lower boundary, even if it is 0, just to be clear.

To be honest, though, I think the 0 based arrays are a leftover from when memory space was a real issue, and by starting with 0, you gained another possible slot with the same size variable. Now, you can just slap a 32 or 64 bit int there and store as many items as you like, because a few bytes more is neglible (and, in some cases, preferable, as the CPU may be faster with types equal to the data bus width, and probably allocates that much for a variable anyway).
 
Top