Reference.Goto History

Hide minor edits - Show changes to markup

October 31, 2008, at 05:14 PM by Paul Badger -
Changed lines 12-13 from:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

to:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

October 05, 2008, at 06:49 PM by Paul Badger -
Changed line 22 from:
            // ... 
to:
            // more statements ... 
October 05, 2008, at 06:48 PM by Paul Badger -
Changed lines 12-13 from:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of the goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

to:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

October 05, 2008, at 06:22 AM by Paul Badger -
Changed lines 18-20 from:

for(int r = 0; r < 255; r++){

    for(int g = 255; g > -1; g--){
        for(int b = 0; b < 255; b++){
to:

for(byte r = 0; r < 255; r++){

    for(byte g = 255; g > -1; g--){
        for(byte b = 0; b < 255; b++){
October 05, 2008, at 06:19 AM by Paul Badger -
Changed lines 14-15 from:

With that said, there are instances where a goto statement comes in handy, and simplifies coding. One of these situations is to break out of deeply nested for loops, or if logic blocks, on a certain condition.

to:

With that said, there are instances where a goto statement can come in handy, and simplify coding. One of these situations is to break out of deeply nested for loops, or if logic blocks, on a certain condition.

October 05, 2008, at 06:18 AM by Paul Badger -
Changed lines 18-21 from:

for(int i = 0; i<50; i++){

    for(int j = 200; j<500; i++){
        for(int k = 0; k > -20; k--){
            if (analogRead(0) > 250) goto bailout;
to:

for(int r = 0; r < 255; r++){

    for(int g = 255; g > -1; g--){
        for(int b = 0; b < 255; b++){
            if (analogRead(0) > 250){ goto bailout;}
            // ... 
October 05, 2008, at 06:11 AM by Paul Badger -
Changed line 17 from:
to:

[@

Changed lines 25-29 from:

to:

bailout: @]

October 05, 2008, at 06:10 AM by Paul Badger -
Changed lines 14-16 from:

With that said here are a couple of instances where a goto statement might come in handy.

  • To break out of deeply nested for loops, or if blocks
  • In a state machine, where it is useful to send program flow to the code for another state in the middle of a block of code.
to:

With that said, there are instances where a goto statement comes in handy, and simplifies coding. One of these situations is to break out of deeply nested for loops, or if logic blocks, on a certain condition.

Example

for(int i = 0; i<50; i++){

    for(int j = 200; j<500; i++){
        for(int k = 0; k > -20; k--){
            if (analogRead(0) > 250) goto bailout;
        }
    }

}

October 05, 2008, at 05:55 AM by Paul Badger -
Changed line 16 from:
  • In a state machine, where it is useful to send program flow to the loop for another state in the middle of a block of code.
to:
  • In a state machine, where it is useful to send program flow to the code for another state in the middle of a block of code.
October 05, 2008, at 05:47 AM by Paul Badger -
Changed lines 12-13 from:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of the goto statement, it is easy to create a program with undefined program flow, which can never be debugged.

to:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of the goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

October 05, 2008, at 05:46 AM by Paul Badger -
Changed lines 14-16 from:

With that said here are a couple of instances where a goto statement might be handy.

  • To break out of deeply nested for loops
  • In a state machine, where it is useful to send program flow to the loop for another state in the middle of a loop.
to:

With that said here are a couple of instances where a goto statement might come in handy.

  • To break out of deeply nested for loops, or if blocks
  • In a state machine, where it is useful to send program flow to the loop for another state in the middle of a block of code.
October 05, 2008, at 05:45 AM by Paul Badger -
Changed lines 12-13 from:

The use of goto is discouraged in C programming, and some authors of programming books claim that it is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the liberal use of the goto statement, it is easy to create a program with undefined program flow, which can never be debugged.

to:

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of the goto statement, it is easy to create a program with undefined program flow, which can never be debugged.

October 05, 2008, at 05:44 AM by Paul Badger -
Changed lines 12-16 from:

The use of goto

to:

The use of goto is discouraged in C programming, and some authors of programming books claim that it is never necessary, but, used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the liberal use of the goto statement, it is easy to create a program with undefined program flow, which can never be debugged.

With that said here are a couple of instances where a goto statement might be handy.

  • To break out of deeply nested for loops
  • In a state machine, where it is useful to send program flow to the loop for another state in the middle of a loop.
October 05, 2008, at 05:34 AM by Paul Badger -
Changed line 12 from:

The use of goto

to:

The use of goto

October 05, 2008, at 05:34 AM by Paul Badger -
Added lines 1-12:

goto

Transfers program flow to a labeled point in the program

Syntax

label:

goto label; // sends program flow to the label

Tip

The use of goto

Share