The most basic operation is the assignment, usually denoted with an "=" sign. For instance in C,Java, Perl , and Python , the statement "a = 2 + 5" means stick the result of adding 2 and 5 into a memory location named "a."
Another of statement controls in what order pieces of your program are executed. C and C-like languages have several of these. "if..else", "while","do..while","for", and "switch" statements all exist.
If and switch statements are used to choose between two or more alternative paths of execution. For example:
if (a <= TOO_BIG) {
a = a + result(a, do_some_stuff(a,b, uncertainty);
} else {
ErrLog.write("a too big\n");
clean_up()
}
switch(a) {
case 1: do_thing_1();
break;
case 2: do_thing_2();
break;
default:
}
While, do..while , and for statements are used to repeatedly execute a block of code until a certain condition is met. For example:
for (a = 0 ; a <= 10 ; a = a + 1) {
do_some_stuff();
}
a = 0;
while ( a <= 10) {
do_some_stuff();
a = a + 1;
}
a = 0;
do {
some_stuff();
a = a +1;
while ( a <= 10);
As you may have noticed all three looping constructs are more or less equivalent in meaning but in any given situation, one of the three is likely to be more intuitive than the others. Before the nineties, these constructs plus function calls and data aggregates , which I'll cover in my next post, were close to all there was to programming languages. Once I cover these basics, I'll start getting into more modern and maybe more interesting ideas, involving GUIs, object oriented programming, and event driven programing.