• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

goto in java:error

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:
I have the code:
class A{
.
.
public void asd()
{
StartEx:
int i;
.
.
goto StartEx;
}
}
When i compile the code i get the error..
'.class' expected
int i;
^
illegal start of expression
goto StartEx;
^
Could somebody help me with why the error occurs.
Thanks,
Preetham.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preetham M,
Welcome to JavaRanch (again)!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No goto in Java.
 
Author
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, no goto. It is a reserved word but you can't use it. Same goes to const.
 
Preetham M
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if i need to make a jump, its not possible in java..
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Preetham M:
So if i need to make a jump, its not possible in java..


Well, trust me - you don't *need* to!
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listen to Ilja's wise advice. I haven't used a goto since I stopped using BASIC in 1978. If you feel that you need to use a goto, it's probably a sign that you need to take a step back and take a look at the structure of your code.
hth,
bear
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still thinking procedurally are we .
 
James Chegwidden
Author
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with the above. You do not need to make jumps. If you want to "jump" you can use a break or continue with a label. This can "jump" in your code.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even in C or C++ you should normally use goto only to exit loops. In Java you do not need goto for this purpose because you can use break labels instead.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!