We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › to sum a repetition
Page Index Toggle Pages: 1
to sum a repetition ? (Read 374 times)
to sum a repetition ?
Mar 13th, 2009, 5:19pm
 
Hi there !

I'm trying to sum results of a repetitions but I didn't find out how to do it.

For example :

Code:
x[0] = 1
x[1] = 2
x[2] = 3

for(int i=0; i<3 ; i++){
????? }



I would like to have x[0] + x[1] + x[2] = 6

I must use a "for" repetition cause there is lot's of operation in it in my sketch, so is possible to sum all the independant x[i] results to get one global x ?
Re: to sum a repetition ?
Reply #1 - Mar 13th, 2009, 5:23pm
 
Just use another variable, say "int sum;" and replace ????? with "sum += x[i];" Without the quotes.
Re: to sum a repetition ?
Reply #2 - Mar 13th, 2009, 5:39pm
 
thanks a lot Cheesy !  it was so simple -_- ...
Page Index Toggle Pages: 1