Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: pber on June 19, 2014, 05:30:58 AM

Title: strange on "n++"
Post by: pber on June 19, 2014, 05:30:58 AM
Hi Charles,

Code: [Select]
int n
dim as string tokens(128)

sub store(string token)
    tokens(n)= token
    n++
End sub

n++ '<<<<<<<< comment this and see the strange behavior

print n
store("xxx")

print n
store("xxx")

print n

...i missed something.
Title: Re: strange on "n++"
Post by: Charles Pegge on June 19, 2014, 05:41:36 AM
Hi Paolo,

Indexbase 1 is the default, - so trying to access element 0, of the tokens array causes trouble.

You can work with indexbase 0, if you prefer, or any other indexbase for arrays. It can be changed at any time and may be confined to local scope, (inside a function, for example)

indexbase 0
Title: Re: strange on "n++"
Post by: Peter on June 19, 2014, 05:52:11 AM
Hi Charles,

you see, indexbase 1 makes lot of trouble for people who are new here.
just change it to 0, what really is standard.

we need no settings  like thinbasic here!   
Title: Re: strange on "n++"
Post by: Charles Pegge on June 19, 2014, 05:59:49 AM
Hi Peter,

The reason why I chose 1 is consistency with character indexing in strings, traditionally 1 to len(s). Iterations are also a bit cleaner: for i=1 to n : v[ i ]= ...

Sophisticated users and developers may opt for indexbase 0, or even indexbase -1 :)
Title: Re: strange on "n++"
Post by: pber on June 19, 2014, 06:06:48 AM
sorry... i could expect some array-related issue.

thanks to all