Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why is "for j = 1 to n" translate to this? Why is the upper bound always incremented by 1?

$$\sum_{j=1}^{n+1}1 $$

Why isn't it $$\sum_{j=1}^n1 $$

"for j = 1 to n" is written in pseudo code btw for algorithm analysis. Or is there a + 1 because of the final condition check when using summations to count the frequency count of for loops?

share|cite|improve this question
It should be what you say it is. I'm not sure why you need to increment it by 1. Are you programming something, by any chance? – Joe Z. Jan 2 '13 at 21:22
Can you provide the context? Where did you see this? Sometimes in programing 0 is the first number, which could cause the difference in notation. – Calvin Lin Jan 2 '13 at 21:25
Saw it in a powerpoint, its written in pseudocode for algorithm analysis – Maximus Programus Jan 2 '13 at 21:27
up vote 1 down vote accepted

I think you are backwards. In BASIC, For j=1 to N gives you N loops, with j=N in the final one. In Python, for j in (1,N) gives you N-1 loops, with j=N-1 in the final one. If you want N loops, you need to do for j in (1,N+1). What language are you working in?

share|cite|improve this answer
its written in pseudocode for algorithm analysis I'm thinking the + 1 is for the final condition check when using summations to count for loops? – Maximus Programus Jan 2 '13 at 21:31
@vincentbelkin: then I don't understand the +1 either. – Ross Millikan Jan 2 '13 at 22:55
To be precise, the Python "for" command loops over the given list and nothing else. It's just that the command "range(a,b)", which is often used to generate the list, produces the numbers $a \le i < b$. – Hans Lundmark Jan 3 '13 at 8:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.