I want to create equation that represents following piece of code (it is much more complicated I simplify it for clearance)

int v = 23; sum = 0; for (int i = v; i > 0; i= i - 2) { sum = sum + i; }

I want to write it like


but I have feeling that it might not be the proper way.

  • $\begingroup$ What is the purpose of creating the equation? The code is probably as good as it gets, in general. $\endgroup$ Apr 7, 2011 at 11:14
  • 1
    $\begingroup$ I need to put in an math article and it must be in a form of equation. $\endgroup$
    – Darqer
    Apr 7, 2011 at 12:34

1 Answer 1


For a finite sum, the order isn't important, and I don't think I have seen a sum where the order was specified as in a for loop.

You can write multiple conditions which have to be satisfied below the $\sum$. For example,

$$\sum_{\substack{p ~\text{prime} \\ p \equiv 1 \pmod 4}} \frac{1}{p^2}.$$

Your sum might be written as

$$\sum_{\substack{0\lt i \le v \\ v-i ~ \text{is even}}} i.$$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .