Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the goto statement in Android [closed]

Tags:

java

android

How can I use goto in Android?

like image 691
sam_k Avatar asked Feb 23 '11 06:02

sam_k


People also ask

How do you use goto statement?

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.

Why is goto not used?

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.

What can I use instead of goto in Java?

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.


1 Answers

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 ;-)

like image 68
maid450 Avatar answered Sep 21 '22 18:09

maid450