aspose file tools*
The moose likes Beginning Java and the fly likes goto statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "goto statement" Watch "goto statement" New topic
Author

goto statement

vijayapriya thirumurugan
Greenhorn

Joined: Apr 03, 2009
Posts: 16


hello sir,

We use goto statement in c. is there any statement like this in java.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

goto is a keyword in java which you cant use in code.i guess if you use goto, you will get compiler error
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Try it and see
James Basller
Ranch Hand

Joined: Sep 07, 2008
Posts: 58
vijayapriya thirumurugan wrote:

hello sir,

We use goto statement in c. is there any statement like this in java.


Hi,

There is no use of goto in Java. Instead of that you can use label in your code.

Thanks,
James
Eric Mission
Greenhorn

Joined: Apr 22, 2009
Posts: 22
Sounds like your method has a logic error if you are trying to use GOTO.

Post your code.

Try using a combination of If Else, Switch, For loop and additional method calls to handle logic.

GOTO explained



to infinity and beyond
Pushkar Choudhary
Rancher

Joined: May 21, 2006
Posts: 425

Here is an old thread that discusses the "goto" in Java.


-Pushkar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Eric Mission, agree. As far as I am concerned, even thinking about "goto" is a logic error.

In fact you can always use a combination of selection repetition and sequence to implement absolutely everything; even your labelled "break" is unnecessary. By the way: it#s not LOOPA but LOOPA:
Eric Mission
Greenhorn

Joined: Apr 22, 2009
Posts: 22
By the way: it#s not LOOPA but LOOPA:

Ah! yes it is- Some days I wish forums had compilers built into them so banging out small examples like that could be syntax checked Alas, I would also like to win the lottery...

even your labelled "break" is unnecessary


So very true, though I figured that if someone was posting a question about a GOTO statement in OOP I thought that by presenting the most basic of basic programming methods I could think of may shine some light for him/her, though probably a mute attempt. Not to mention providing an example of using a label as James suggested.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Eric Mission wrote:. . . I wish forums had compilers built into them . . .
Just at the moment we are having difficulty with delays for ordinary text, so no chance of a free compiler
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

seetharaman venkatasamy wrote:goto is a keyword in java


Wonder why did they reserve the Goto keyword


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18747
    
  40

We use goto statement in c.


I have to challenge this... no C programmer worth his salt should be using the goto statement. I used C for many years, including device drivers, network drivers, kernal code, etc. And I have never used goto... Well, except once, due to time constraints, and I went back and got rid of it. If it was Java, I would have been forced to do it correctly the first time.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
I read somewhere that the goto keyword was retained so compilers could throw better error messages. Can't remember where. Sorry.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
"Chuck Norris is the only one who can use goto and const in Java."

SCJA
~Currently preparing for SCJP6
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Brian Legg wrote:"Chuck Norris is the only one who can use goto and const in Java."

http://www.chucknorrisfacts.com/

*edit*: Oh, just discovered this topic in the Meaningless Drivel forum!


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
 
subject: goto statement