Why the list index start from 1 in the Ring programming language

Hello

It’s about how we count in the real world, when we have three apples in our hand

we say 1 2 3
We don’t start from 0

The question must be why the other languages start from 0 ?
The answer is, because this is related to the machine and how we deal with values and memory address

Example

we have array called myarray[5]
in memory : myarray will have an address
The first item will be stored in that address
the second item will come after that address and so on
now when we need to point to the first item we need the address of myarray
so we type myarray[0] because myarray + 0 result will still point to the first item
for the second item myarray[1] because myarray + 1 result will point to the second item and so on

In Low Level languages or languages near to the machine it’s good to be like this

But for high level language designed for applications it’s better to be natural

Example

mylist = [1,2,3,4,5]
for x = 1 to len(mylist)
see x + nl
next

in the previous example we start from 1 to the length of the array
if the index starts from 0 we will write

for x = 0 to len(mylist)-1

or remember the for loop in other languages

for(x=0 ; x<nMax ; x++ )

you will use the < operator !

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s