“goto” Statement
Up to now we have covered the basic programming constructs.
These include sequences, decisions and repetition structures (i.e. loops). In
sequences, we use the simple statements in a sequence i.e. one after the other.
In decisions construct we use the if
statement, if/else statement, the multi way decision construct (i.e. the switch statement). And in repetition
structures, we use the while, do-while
and for loops.
Sometime ago, two computer scientists Gome and
Jacopi proved that any program can be written with the help of these three
constructs (i.e. sequences, decisions and loops).
There is a statement in the computer languages
COBOL, FORTRAN and C. This statement is goto
statement is used to jump the control anywhere (back and forth) in a
program. In legacy programming, the programs written in COBOL and FORTRAN languages
have many unconditional branches of execution. To understand and decode such
programs that contain unconditional branches is almost impossible. In such
programs, it is very difficult, for a programmer, to keep the track of
execution as the control jumps from one place to the other and from there to
anywhere else. We call this kind of traditional code as spagatti code. It is
very difficult to trace out the way of execution and figure out what the
program is doing. And debugging and modifying such programs is very difficult.
When structured programming was started, it was urged not to use the goto statement.
Though goto is there in C language but we will not use it in our
programs. We will adopt the structured approach. All of our programs will consist
of sequences, decisions and loops.
No comments:
Post a Comment