Control flow

Control structures ( control constructs) are instructions in imperative programming languages. They are used to control the flow of a computer program. A control structure is either a branch or a loop. Most of their execution via logical expressions of Boolean algebra is affected. Control structures can be visualized using special charts (eg Nassi- Shneiderman diagrams).

History

In the early 1960s, flowcharts and jump statements were common in programs that larger programs made ​​almost unmaintainable, as they were quickly unmanageable. Edsger W. Dijkstra in 1968, said in his essay Go To Statement Considered Harmful (the title, however, goes on Niklaus Wirth back ), for the abolition of the GOTO command in all higher programming languages ​​.

May, 1966 Bohm and Jacopini published in the journal Communications of the ACM an article in which they showed that any program that contains goto instructions, can be rewritten in a Goto - free program that only with branching (IF THEN ELSE ) and a loop (WHILE condition DO statement) works, possibly with the aid of some code duplication and the introduction of Boolean variables (true / false).

Early 1970s was begun to implement this approach to self-restriction to a few typical elements. Leading the way was the work of Niklaus Wirth with his programming language Pascal.

Concept is an example of

Without control structures reps and conditions need to jumps ( GOTO, IF ... GOTO - English: jump to ... When jump to ) be realized. The output of the numbers from 1 to 100, but without the range 40 to 60 is realized without control structure like this (pseudo code, with reference to BASIC)

I: = 1   M1: PRINT I - Version of I       IF I = 39 THEN GOTO M2 - If ... jump ( conditional execution )       I: = I 1       IF I < = 100 THEN GOTO M1 - If ... jump ( repeated execution )       END - End of program   M2: I: = 61       GOTO M1 - leap M1 Unstructured Program: Output of the numbers 1, 2, ..., 39, 61, 62, 63, ..., 99, 100 The use of control structures is also part of structured programming. Each control structure consists of at least one start and one end mostly keyword. Languages ​​such as Pascal, C, Modula -2 ( and also newer versions of the BASIC language ) have control structures for repetition

REPEAT        instructions      UNTIL condition and conditional execution of instructions:

IF condition THEN         instructions      ELSE         instructions      ENDIF The key frame this one the instructions which are executed repeatedly or conditionally. The above programming task can then be implemented as follows:

I: = 1       REPEAT - Repeat          PRINT I          IF I = 39 THEN - If ... Then             I: = 61          ELSE - Otherwise             I: = I 1          ENDIF - End If       UNTIL I> 100 - to       END - End of program Structured Program: Output of the numbers 1, 2, ..., 39, 61, 62, 63, ..., 99, 100 The program has a structure which is still mostly indicated by indentation. The new key and the format to facilitate the understanding of the program code.

Avoidance of Goto

Control structures unclog with Goto avoid because almost any programming task with the help of condition and repetition structures can be solved. Goto programming without using a modern language is the norm today. The Java programming language supports eg no goto statement more.

Is dispensed to some of the freedoms. In the above example will I> 100 queried at I = 39 in the structured variant anyway, although this is not really necessary. An optimizing compiler could correct this though, but probably not in all cases, be able to recognize such subtleties.

The use of control structures prevents the development of source code, in which, on confusing way back and hergesprungen. The following features characterize a program with the use of control structures:

  • Instructions that are repeated are clearly characterized by Keyword
  • Conditions and repetitions are instantly recognizable
  • Avoidance of Goto and Labels

Flow diagrams and structure charts

Flow diagrams for the graphical representation of the program flow. You have the same freedoms offered by Goto in the program code. In 1972, I. Nassi and B. Shneiderman the idea flowcharts to be replaced by structure diagrams in which control structures are represented by graphical elements, the Nassi- Shneiderman diagrams. Structure diagrams can then be put into a structured program code.

The unstructured code to output the numbers 1 to 39 and 61-100 can be represented by a flow chart:

Also, the structured code could be represented by a similar diagram but in addition by a structure chart

485871
de