How can I use goto
in Android?
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. That being said, goto can be useful sometimes. For example: to break from nested loops.
NOTE − Use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten to avoid them.
Use a labeled break as an alternative to goto. Show activity on this post. Java doesn't have goto , because it makes the code unstructured and unclear to read. However, you can use break and continue as civilized form of goto without its problems.
Tha language used in Android is Java, and there isn't any goto
by itself in Java.
You can use a labeled break
or other alternatives as described in an answer to Stack Overflow question Alternative to a goto statement in Java, but these constructs should be avoided as long as possible, as they produce really ugly and hard-to-maintain code.
Just figure out how to design your code correctly, and you will never need goto
and such stuff ;-)
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