answersLogoWhite

0

Edsger Dijkstra said, excessive usage and unstructured usage of goto may:

1. lead to a very bad/un-readable/un-structrured/complicated code

2. increase the complexity of debugging and analyzing the code

.

But there are some hidden-gotos that we use in C language

1. break

2. continue

3. return

.

Rules of thumb:

It is not very bad to use goto in any language if we follow the following rules

1. Always use gotos to jump to a forward location. Gotos are very useful in cleanup activities

2. Backward jump can always be accomplished by using continue inside a loop. This doesn't mean that we shouldn't use backward gotos. Backward gotos can be introduced when the code is very legible and it is not disrupting the structure and readability of the code and there are only a few backward gotos.

3. Use do { .... if(xx) break; ... } while(0); - type of coding will suite to most of the places where we need to use goto.

4. Usage of goto to jump into another code-block/scope is always bad. Instead strucure the code in such a way that goto-lables are placed at the start of the code-block/scope.

5. The primary-advantage of using goto when compared to its alternative ways is, goto is fast.

6. Avoid as much gotos in your code and use goto only when you feel that usage of goto's alternative ways will slowdown the execution or they increase the complexity or decrease the readability.

7. Make sure that usage of goto/break/continue/return is not creating any unreachable code

8. Keep in mind that usage of goto is near to punishable offence w.r.t some organization's/intuition's coding standards.

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Write a c for goto statement?

AGAIN: puts ("c"); goto AGAIN;


Which statement is not frequently used in C plus plus?

The goto statement.


Explain goto and return in c?

A return statement is used to transfer the program control flow to the function that has called the current function under execution. If the function is main, then the program returns the control flow to the operating system. The syntax for return statement is:return return-type;A goto statement is used to transfer the control flow to a particular labelled statement, not necessarily back to the calling program. There are somerestrictionson using a goto statement. For eg: the goto statement should not skip any variable declarations. The use of goto statement is usually considered as a bad programming practice. The syntax for goto statement is:goto label_name;....label_name: statements;


Is there any other keyword like goto in c plus plus?

The goto statement is a control flow statement that causes the CPU to jump to another spot in the code. This spot is identified through use of a statement label. The following is an example of a goto statement and statement label:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> #include <cmath> int main() { using namespace std; tryAgain: // this is a statement label cout << "Enter a non-negative number"; double dX; cin >> dX; if (dX < 0.0) goto tryAgain; // this is the goto statement cout << "The sqrt of " << dX << " is " << sqrt(dX) << endl; }


What is null statement?

in C: a semicolon in itself. Examples:1. while (*to++ = *from++);2. { goto END; ... END:; }

Related Questions

Write a c for goto statement?

AGAIN: puts ("c"); goto AGAIN;


Which statement is not frequently used in C plus plus?

The goto statement.


What is looping statement in turbo c?

while, for, do-while (and perhaps goto)


Explain goto and return in c?

A return statement is used to transfer the program control flow to the function that has called the current function under execution. If the function is main, then the program returns the control flow to the operating system. The syntax for return statement is:return return-type;A goto statement is used to transfer the control flow to a particular labelled statement, not necessarily back to the calling program. There are somerestrictionson using a goto statement. For eg: the goto statement should not skip any variable declarations. The use of goto statement is usually considered as a bad programming practice. The syntax for goto statement is:goto label_name;....label_name: statements;


Which statement should normally be avoided in c programme?

The word your teacher wants to hear is 'goto'.


Is there any other keyword like goto in c plus plus?

The goto statement is a control flow statement that causes the CPU to jump to another spot in the code. This spot is identified through use of a statement label. The following is an example of a goto statement and statement label:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <iostream> #include <cmath> int main() { using namespace std; tryAgain: // this is a statement label cout << "Enter a non-negative number"; double dX; cin >> dX; if (dX < 0.0) goto tryAgain; // this is the goto statement cout << "The sqrt of " << dX << " is " << sqrt(dX) << endl; }


What is null statement?

in C: a semicolon in itself. Examples:1. while (*to++ = *from++);2. { goto END; ... END:; }


Why goto in c is a bad command?

A 'goto' statement immediately moves the execution of code to another part of the program. This makes the code difficult to follow and to debug. It is better practice to use If-then-else constructs to structure the program code.


How many arithmetic statement in c?

Only one: expression. Yes, in C expression is one of the statements. Some other statements are: if, do, goto, while, for, switch, break, continue, return, NULL-statement, compound-statement.


Difference between goto and continue statement in c language?

In continue statement, we immediately continue next step through loop In go to statement, we go to in perfect label which we call.


Why is goto statement harmful?

It isn't. True, you can write bad code with goto, but you can do that without goto as well.


Why goto is not a good structured programming style?

goto is a statement, not a programming style.