1 + 2 + 3 + ... + N
using a loop. Partial sums are accumulated in the variable N
for(i = 1; i <= N; i++ )
s := s + i;
// more idiomatic version:
for(i = 1; i <= N; i++ )
s += i;
The first clause in for( *; *; *) initializes the loop counter. The second tests to see if the current loop counter is valid. The third increments it by one unit. This is the syntax in general: initialize counter; test it; increment it.
The body of a for loop can be a block, i.e., a sequence of statements enclosed by curly braces:
for(i = 1; i <= N; i++ ) {
s := i;
printf("sum(%d) = %d\n", i, s);
}