I want to skip some line of code by checking if condition in the same method. I used goto statement but it showed "cannot jump from this goto statement to the label". Is there any other way I can skip code? what I do is..
if(condition)
goto skipped;
//code to skip
//code to skip
skipped:
//code to execute
The use of goto statement may lead to code that is buggy and hard to follow. For example, one: for (i = 0; i < number; ++i) { test += i; goto two; } two: if (test > 5) { goto three; } ... .. ... Also, the goto statement allows you to do bad stuff such as jump out of the scope.
The goto statement is a jump statement which is sometimes also referred to as unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function.
A goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function.
In the C programming language, the goto statement has fewer restrictions and can enter the scope of any variable other than variable-length array or variably-modified pointer.
There are surely legitimate uses for goto, so I think this deserves a proper answer:
Some possible reasons why you might be failing:
Read more : http://en.cppreference.com/w/cpp/language/goto
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With