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.
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
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!
Yes, no goto. It is a reserved word but you can't use it. Same goes to const.
Mr. C<br /> <br />Author and Instructor<br />My book:<br /><a href="http://www.aw-bc.com/catalog/academic/product/0,1144,1576761614,00.html" target="_blank" rel="nofollow">http://www.aw-bc.com/catalog/academic/product/0,1144,1576761614,00.html</a>
Preetham M
Greenhorn
Joined: Sep 18, 2002
Posts: 12
posted
0
So if i need to make a jump, its not possible in java..
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
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!
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
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
"JavaRanch, where the deer and the Certified play" - David O'Meara
James Chegwidden
Author
Ranch Hand
Joined: Oct 06, 2002
Posts: 201
posted
0
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.
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
posted
0
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.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.