# Can you write a for-loop with an iteration > 1 in summation form

If you were to take the following for-loop:

for (int i = 1; i <= 50; i++) {}


And write it in mathematical form, it would look something like this:
$\sum\limits_{i=1}^{50}i$

Each interval of the above sequence would be the same as each interval i of the above for-loop

the $50$ is the maximum number, the "$i=0$" is the starting point, but what about the iterations. all of them seem to have to do with $i$ being the current index of the sequence.

How would I write something that has iterations that are greater than one?

Meaning:

Is there a way of writing this:

for (int i = 1; i <= 50; i += 3) {}


in summation form?

-
$\sum f(1+3k)$, where the sum is over all $k$ such that $1 \le 1+3k \le 50$. Actually, your loop doesn't sum anything, it just increments $i$ until it reaches (or exceeds) $50$. – GEdgar May 4 '12 at 17:23
How is a for-loop with no action in any way "equivalent" to a summation over all integers from $1$ to $50$? – TMM May 4 '12 at 17:27
@TMM - System.out.println(i); – Ephraim May 4 '12 at 17:28
@Ephraim: Then your algorithm prints 1 2 3 ... 50 while $\sum_{i=1}^{50} i \equiv 1275$. – TMM May 4 '12 at 17:30
@TMM - I was referring to to each interval of interval of the sequence, not the actual final summation. but if you want it to be the summation, I would just add int v = 0; above the loop, v +=1 inside of the loop, and and system.out.println(v); after the loop. But the point of my question is still the same. – Ephraim May 4 '12 at 17:33

To get a sequence of integers with a gap of $d$ and a starting point of $a$, you want $kd+a$ for $k=0,1,2,\dots$. In your example that would be $3k+1$ for $k=0,1,2,\dots$. Thus, you your summation is $$\sum_{k=0}^nx_{3k+1}=x_1+x_4+x_7+\ldots+x_{3n+1}\;.$$ (I'm using $x$ as the generic name of whatever you're summing.)
Now you want to find the right $n$. Here you want $3n+1$ to be as large as possible while not exceeding $50$. $3n+1\le 50$ if and only if $3n\le 49$ if and only if $n\le\frac{49}3$, but you want $n$ to be an integer, so $n=16$: $$\sum_{k=0}^{16}x_{3k+1}\;.$$
In general, if the upper limit on the subscript is $L$, you'll want $n=\left\lfloor\frac{L}d\right\rfloor$.