- Variables can receive values directly at the declaration:
Abbreviation Stands for
var x = 0; var x; x = 0;
- If a variable in an update appears on bosth sides of an
assignment, then one can in certain cases save one occurrence
of the variable:
Abbreviation Stands for
x += 5; x = x+5;
x -= 18; x = x-18;
x *= y+z; x = x*(y+z);
x /= y+z; x = x/(y+z);
Note that the brackets are necesasry on the right hand side;
for example compare the results of the two variables v and w
after the loop
var v=1; var w=1; var u;
for (u=0;u<9;u++)
{ v *= u+1; w = w*u+1; }
at the end of this page.
- The operators "++" and "--" add and substract 1 to and from
a variable, respectively, after it is read.
Abbreviation Stands for
c++; c = c+1;
c--; c = c-1;
while(c++<9) { X; } while (c<9) { c=c+1; X; }
Note that the name of the programming language "C++" refers to
this abrevation indicating that it is obtained by "incrementing"
C, that is, by adding the concpets of object-oriented programming
among other modifications.
- The for-loop can also be interpreted as an abbrevation. Assuming
that A, C, D are statements and B is an Boolean expression, the
following are equivalent.
Abbreviation Stands for
for (A;B;C) D; A; while (B) { D; C; }
Note that the statement C comes after D and not before.
The statement D itself can consist of several statements
and so "D; " can actually be "{ D; E; }". Anyway, it is
good style to write "{ D; }" instead of "D;" in a for-loop.
Implemented are a formula to compute 0+1+2+...+z, a fast loop and
a slow loop to do this. This initial value of z is 25000000. There
are three ways to do it: the formula of Gauss, an optimized fast loop and
a nonoptimized slow loop. Of course, an algorithmic improvement like
the one of Gauss outperforms the code-optimization (fast loop), but
nevertheless the code-optimization can be very helpful in cases where
such an improved algorithm does not exist.