Which Programming Languages Index by One?

Which Programming Languages Index by One? Featured Image

Recently, I wrote an article about why programming languages tend to use zero-based indexing. At least in my experience, the vast majority of programming languages do. Of course, that got me wondering: how many programming languages actually index by one? That’s the topic of today’s article.

Table of Contents

What Is Indexing?

If you clicked on this article, chances are you’re already familiar with the concept of indexing. That said, for completeness, let me take a moment to talk it out.

Any time we’re working with a linear data structure like a list or array, we’re likely able to poke around that data structure using an index. For simplicity, an index is a key into a list. Usually, we use integers, but I suppose you could use anything.

Of course, if we’re going to number items in a list, we have to agree on a convention. Specifically, what do we number the first element? This question typically raises one of three possible answers:

  • Start at 0
  • Start at 1
  • Start at anything else

Because most programming languages start from zero, you might be surprised to hear that there are actually languages that start from one. The two that come to mind for me are Lua and MATLAB. As it turns out, those languages aren’t alone. In the next section, I’ll share a list of languages that index from one.

Programming Languages With One-Based Indexing

As someone who has worked with a lot of programming languagesOpens in a new tab., I find this kind of task to be right up my alley. That said, I don’t claim to be an expert on this topic. As a result, with each programming language I list out, I’ll also share some sources that can back me up.

  1. Algol-60
  2. Algol-68
  3. APL
  4. AWK
  5. COBOL
  6. Fortran
  7. FoxPro
  8. Julia
  9. Lua
  10. Mathematica
  11. MATLAB
  12. R
  13. Sass
  14. Smalltalk
    1. Programming Languages Where Indices Start from 1 (NOT 0)Opens in a new tab.

Ultimately, there are not many languages with indexing from one, but there is a somewhat common thread for the languages that do: math. It seems that many of the languages that prioritize math is some form (e.g., MATLAB, Julia, Mathematica, etc.) all use one-based indexing.

Why Should We Care?

At the end of the day, it doesn’t really matter how a programming language approaches indexing. In the past, it had bothered me how much zero-based indexing confused students, so I struggled to pick a side. These days I’ve realized it doesn’t really matter. Though to some folks, it really does matter, and those are folks you probably don’t want to spend your time with:

Starting with index 1 is meaningful only in cases you're not doing any computation on the index value itself... but then you could start from 14 too without much problems either. If the actual numeric value of the index is used for computations then you will find that in most cases the correct index for the first element is 0 (e.g., polynomial terms where the index is also used in exponent).
Indexing By Zero: Part 2
Indexing From Zero: Part 3

All I can say is this guy must be really fun at parties.

At any rate, that’s all I have to share about one-based indexing. If you enjoyed this article, here are some more like it:

And if you really enjoyed this article, why not show your support? Otherwise, I’ll see you next time!

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts