my dog learned polymorphism*
The moose likes Java in General and the fly likes The Java equivalent to the C and C++ goto Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "The Java equivalent to the C and C++ goto" Watch "The Java equivalent to the C and C++ goto" New topic
Author

The Java equivalent to the C and C++ goto

peter m hayward
Ranch Hand

Joined: Sep 27, 2012
Posts: 35
Hi guys I am have some difficulty jumping back to a line in the code given the there goto is not supported my set up is java 7.2 I have graduated from C programming to java hence the problem !
The object is the remove the wrapping from the authors i a string containing an unknown number of authors , in this example i just repeat the same author but in real life they will be different, so what i need to do is pull out each and process it so i end up with the authors without the wrappings
[{Dr}{Seuss}][{Dr}{Seuss}][{Dr}{Seuss}] initial string
Dr Seuss, Dr Seuss, Dr Seuss required string with separating comas and non at the last author

What is have done so far is to check the length of the string so i can run a loop till all chars have been processed
Then i detected in that loop the occurrence of “ ] [ “ thus counting the number of authors
Next I find the end of the string }] and the start of the last element in the string [{ so now i am in a position to create a sub string and put the results in an array next i reduce the author count by one and if non zero i need to get back to the top to start over and if the new reduced string was the original input
[{Dr}{Seuss}][{Dr}{Seuss}] this being the sub string and then the loop needs to run again to give [{Dr}{Seuss}] and finally author count equals zero then i will drop out of the loop and process what has been put into the array to complete the desired output Dr Seuss, Dr Seuss, Dr Seuss
I call the class from main like this



fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11351
    
  16

So not to be obtuse, but do you have a question that you need help with?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Your question is not clear. Please share problem statement.


Vinod Tiwari | Twitter
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

I think I understand his question, he is "decently clear." He wants a goto statement, which to me sounds like you want to do some methods (which you don't have any in your code)

If you do

then when you need to call a certain code fragment you just do

if your'e asking how to goto a certain line, I'm not too sure, but with methods and such you should be able to complete what you need to.
peter m hayward
Ranch Hand

Joined: Sep 27, 2012
Posts: 35
Hi Guys Jay Orsaw gave me what i was looking for just could not see it at the time as i was fixated on the goto C legacy in my brain now it works just fine by putting an method call where i need it.

also sorry i forgot to point out that i had marked the code where i need to get to

any thanks to you all another one done and dusted

pete
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

peter m hayward wrote:Hi Guys Jay Orsaw gave me what i was looking for just could not see it at the time as i was fixated on the goto C legacy in my brain now it works just fine by putting an method call where i need it.

also sorry i forgot to point out that i had marked the code where i need to get to

any thanks to you all another one done and dusted

pete


Hehe yeah no worries, a lot of people say C is like Java, but there are a ton of differences. I really love Java, so I hope you enjoy it also, and welcome!
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
Jay Orsaw wrote:a lot of people say C is like Java, but there are a ton of differences.


I'd rather say the other way around: Java is a member of the C family of languages.

About "goto" first let me paraphrase a well-known citation:
If you want X, you know where to find it.

If you want "goto", you know where to go for it ;-)

Anyway, I was kidding.

A sidenote: I did C for a while and I do not remember even having needed/used goto.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Java equivalent to the C and C++ goto