Cloudbook: C

  1. Home
  2. Control
  3. If/Else
  4. § 1 exercise →
If/Else

We have learned a bit about variables and about logical expressions. So far all of our programs were a sequence of statements to be run in the order written. Such programs are very predictable. It becomes a lot more fun when statements can be run in different orders.

The simplest modification is to collect a squence of statements together into a single unit, called a block, and to run the block zero or more times, according to some sort of controlling expression. To run a block means to run each statement in the block, in the order the statements appear, beginning with the first, and ending with the last.

After the last statement is run, either the block is rerun from the first statement, or the program continues with the next statement in the program — that will depend on how the controlling expression is applied. Also, the controlling expression might decide that the block will not be run even once, it will be immediately skipped over and the program continues with the statement after the block.

A block is like a digression which one enters into, and leaves from, nested within the original argument.