• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The Java equivalent to the C and C++ goto

 
peter m hayward
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So not to be obtuse, but do you have a question that you need help with?
 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is not clear. Please share problem statement.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic