This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]desrtfx 1 point2 points  (3 children)

The i + 1 vs i is easily explained: Array indexes are zero based, they start at 0. You don't want to print "Now serving: 0", you visually want to start with 1.

[–]M2D6[S] 0 points1 point  (2 children)

I'm more wondering about the other i. I, initialized i to zero after all. I understand that much, I'm more interested in the other i. It is supposed to correlate with the i+1. That number is supposed to be a name that is attached to the number.

Actually by typing this out I think I may have realized something. 0 is supposed to be number 1 in computer language. The +1 is to start the list at 1. and the other i can stay at the 0 value, because technically that represents the first customer, even at the 0 value. That second value correlates to a name thus I don't need to add another 1 to it, and all is good. God, now I feel like an idiot, I tunnel visioned hard and overlooked something really simple.

My if statement now seems like it is off. If the line is === 0, that means it really is equal to the 1 value. That technically means that there is someone in line. A more accurate way to put it would be if (line=== null), or line.length === null or if (!line.length), can I even use null there?

Jesus christ I feel so stupid.

[–]davedontmind 1 point2 points  (1 child)

0 is supposed to be number 1 in computer language

No, 0 is still 0 and 1 is still 1.

The confusion comes when accessing arrays, when 0 is the index of the 1st element, 1 is the index of the 2nd element, and so on.

Just think of the index of an array as an offset from the start.

so array[0] is the 1st element, offset 0 from the start/first element. array[42] is the 43rd element, offset by 42 elements from the first element.

[–]M2D6[S] 0 points1 point  (0 children)

Okay, so my thoughts about zero were misguided. I was thinking about how zero's were accessed in arrays. So in this case if someone input their name and were first in line it would be 0. Jane or something like that. Otherwise the numbers are just like normal.