Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

goto statement

 
vijayapriya thirumurugan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hello sir,

We use goto statement in c. is there any statement like this in java.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it and see
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an old thread that discusses the "goto" in Java.


-Pushkar
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:goto is a keyword in java


Wonder why did they reserve the Goto keyword
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Chuck Norris is the only one who can use goto and const in Java."
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic