Why for i equals one?

Programmers can skip to the next heading as I’ll just be explaining a basic for loop here.

In programming you often want to repeat a bit of code (a set of instructions for the computer) a certain number of times. Maybe you have data in a list (an array), say a list of five names, and you want to print each of them to the screen. To do that easily, you create a for loop.  In simple terms, you tell the computer where to start, where to finish, and how to get from one step to the next. So in English you’d maybe write, “Start at 1 and go to 5, increasing the count by 1 each time.” In programming, though, you’d usually say, “Start and 0 and go to 4.” I won’t explain why programmers start counting at 0 right now.

So in some common programming languages, like C and Java, you’d write
for (int i=0; i<5; i++)

The above code is very common. i is the counter variable, possibly coming from “index” or “integer” (the int declaration states that i is an integer). So i starts at 0 (i=0). It will continue to execute the code as long as i is less than 5 (i<5) and each time the code is executed, i is increased by 1 (i++ is shorthand for i=i+1).  So the code will execute 5 times, when i=0, i=1, i=2, i=3, and i=4, but once i=5, it will stop because i is no longer less than 5.

Why i=1?


Since programmers usually start counting at 0, why does my for loop start at 1 and why is that the title for this blog? Because sometimes it does make sense to start at 1. The usual way a programmer would start their career in programming is by getting a computer science degree in college. In my analogy that would be starting at 0.

I didn’t start there. I actually got a degree in Pastoral Studies and served as a pastor for 15 years. But then I felt like it was time to do something different. Thankfully, all the while I was pastoring I had a part-time job where, after being hired for data entry, I ended up programming Microsoft Access. That job has transitioned to where I am full-time and writing in OmniScript, a proprietary script language. I’m enjoying that and am very thankful to have a job in programming in my forties without any formal training, however, I want to learn more. And so for the past year I have been learning more about more popular programming languages. I’m doing that on my own through several great online resources. So this is my i=1.

for (int i=1; i<finished; i++) 

This is where I’m starting. I didn’t start at 0 but it’s not too late, i<finished (I am less than finished). i++, I keep learning more every day and am having a lot of fun at it.

What will this blog be like?


First I’m going to recount the various steps in my non-formal programming background, how I got to the point where I was able to get a full-time job in programming in my forties.. Then I’ll be writing about all that I’ve learned this past year about programming methodology and various languages, which has been a lot. Then I’ll just keep on writing as I continue to learn more in this fun journey. If this is of any interest to you, I hope you’ll come back and join me.

i++

No comments:

Post a Comment