7

How can I use goto in Android?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
sam_k
  • 5,887
  • 13
  • 73
  • 108
  • "goto" who told you it is supported...if you know java then you might be knowing that it is not supported in java itself....;-)..... – N-JOY Feb 23 '11 at 06:15
  • 1
    @reno is it an OS? i thought it is software stack.... – N-JOY Feb 23 '11 at 06:17
  • 4
    I don't see how this is "not a real question". How to use a goto statements in Android might be asking the wrong question, but there still is an answer, and it's potentially useful for other people who mix up Android and Java. – Brendan Long Feb 24 '11 at 02:41

2 Answers2

7

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

Community
  • 1
  • 1
maid450
  • 7,438
  • 3
  • 36
  • 32
6

If you are using the Android SDK in Java you cannot use a goto statement. Java does not provide a goto statement in its grammar.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
bschaffer13
  • 200
  • 1
  • 8