Thursday, April 14, 2005

Control Structures

Introduction

Structured programming is about getting rid of goto statements. In order to do so, we need to abstract away from goto statements, and replace gotos with control structures. Actually, Java programmers do not have a choice, since Java do not have the goto statement.

Discussion

Even if Java does not have a goto statement, the keyword goto is reserved. The idea is that the Java compiler may produce better error messages if the keyword goto is used (JLS3 2005).

It has been shown that any program can be written, without the goto statement, using only the control structures sequence, conditional and iteration.

Note: In 1964 Corrado Bohm and Guiseppe Jacopini proved the Structure Theorem. The theorem states that any algorithm can be expressed using only three basic control structures Sequence, Conditional and Iteration.

References

Resources