Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

goto statement in Javascript?

Status
Not open for further replies.

Kathy1

Programmer
Dec 21, 2000
39
0
0
US
Hi All.

This might be a silly question, but is there the equivalent of a 'goto' statement in Javascript? Most languages have one, but all the documentation I've gone through, and searches I've done, have turned up nothing of the sort for Javascript.

Thanks!

Kathy :)
 
Thanks Jaredn.

The break statement isn't exactly what I was looking for...I was trying to not have to put a bunch of code into an 'if' statement. Just wanted to branch around it. However, I may just put it into a subroutine, which would make the 'if' statement code alot cleaner.

Appreciate your help! :)

Kathy
 
I've been programming for over 20 years, and in any properly structured language (of which JS is one) I have NEVER found that I needed a goto statement. There is always a way around using it. True, as you mentioned it may make the code a little more efficient, but it can also confuse things. I think your solution of putting things into a subroutine to make the code clearer is a good idea. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi Tsdragon.

I am used to coding mainframe COBOL, which often uses the 'goto' statement to get out of a subroutine by going to the subroutine 'exit' in specific situations. What we are doing is converting COBOL mainframe insurance policy rating systems into Javascript, HTML, Perl, and SQL for the Internet and our Intranet. I do understand that arbitrarily using goto's is not good programming practice - especially if you are jumping all over the place. Makes the programming very difficult to follow, makes maintenance a nightmare, doesn't follow the old-fashioned top-down approach (that was before oop, of course), etc... I've worked with many nasty programs like that. Don't make a habit of writing them, though. Just had a situation where a 'goto' would have been useful, and was wondering if one existed in Javascript, since I'd never seen it.

Thanks for your input!

Kathy :)

 
Kathy, that's why I specifically mentioned properly structured languages. I was thinking of COBOL when I made that qualification. When I started programming I was doing IBM mainframe programs in COBOL and used goto for the same purpose you mentioned. But then COBOL is definitely NOT a properly structured programming language. It does complicate trying to do an simle conversion, but it will be worth it in the long run.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top