473,544 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why doesn't JavaScript have a goto command?

Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.

Mar 7 '06 #1
34 26600

el*********@ele ctrician.com wrote:
Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.


Javascript does indeed have a "goto" keyword but is just a reserved
keyword.

It is not the matter of difficulty of implementation but rather the use
of "goto" statements that generally leans towards spaghetti code. And
yes, it can also be argued that very conservative use of the statement
can be helpful at times.

Here's a very classic article:

title: Go To Statement Considered Harmful
url: http://www.acm.org/classics/oct95/

Mar 7 '06 #2
el*********@ele ctrician.com wrote:
Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say
go to it.


There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 7 '06 #3

<el*********@el ectrician.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.


Because, if you need to use a GOTO, then you are doing something wrong.
Mar 7 '06 #4
Noozer wrote:
<el*********@el ectrician.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.


Because, if you need to use a GOTO, then you are doing something wrong.


Not at all, sometimes you have to get out of two loops and with a goto
you can achieve this easily, goto is a reserved word, but JavaScript
has labels.

while(confirm(" ok?"))
MyLabel:
while(1)
while(1)
break MyLabel;
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Mar 7 '06 #5
Noozer wrote:
<el*********@el ectrician.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.

Because, if you need to use a GOTO, then you are doing something wrong.


Ever program in Assembly?
Mar 7 '06 #6
<There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)


So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts? I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.

Mar 8 '06 #7
Zif
el*********@ele ctrician.com wrote:
<There is no logcal need for goto.

The lack of goto forces you to think of the correct way to solve your
problem, rather than relying on spaghetti code :)
So what about those of us that like programming in spaghetti code? Who
are you or the creators of JavaScript to force me to use their
programming concepts?
Someone has a gun at your head, forcing you to use JavaScript? Heck, you
must be one gun programmer.

You can't even be bothered to publish web pages that accommodate
browsers other than IE, why should anyone care about your opinion?

I like Goto and want it and have worked for
hours to try something else when goto would have saved me precious
time. This is another example of academia forcing us to use useless
non productive time to preserve some higher than thou intellectual crap.


But you'd like to force them to implement goto because you want them
too? Because it fits with your concept of programming learned where?
What substantive argument can you provide to show that goto is of any
benefit to JavaScript?

Your 'calculator'[1] stands as a public record of your programming
ability. Claiming ignorance of standards and design principles as a
virtue does not make it so. Did you fix the errors that were pointed
out to you?
1.
<URL:http://groups.google.c o.uk/group/comp.lang.javas cript/browse_frm/thread/3b545c991e656da 6/4355f865f033ecb e?q=How+do+you+ stop+a+javascri pt+program%3F&r num=1#4355f865f 033ecbe>

--
Zif
Mar 8 '06 #8
Jonas Raoni wrote:
Noozer wrote:
<el*********@ electrician.com > wrote in message
news:11****** *************** *@i39g2000cwa.g ooglegroups.com ...

Perl has it, Basic has it, Fortran has it. What is so difficult about
creating a goto command for JavaScript. Just set up a label and say go
to it.


Because, if you need to use a GOTO, then you are doing something wrong.

Not at all, sometimes you have to get out of two loops and with a goto
you can achieve this easily, goto is a reserved word, but JavaScript
has labels.

while(confirm(" ok?"))
MyLabel:
while(1)
while(1)
break MyLabel;

That is not the typical use of goto. A better pseudo-code example would be:

while (...){
if (...) {
goto foo;
} else if (...) {
goto bar;
}
}

foo: { }
bar: { }

But you can achieve the same result without using goto.

goto is long dead. If you want to support it's revival, present a
scenario where it is required, or where it is significantly more
efficient than existing methods.
--
Rob
Mar 8 '06 #9
RobG wrote:
Jonas Raoni wrote:
That is not the typical use of goto. A better pseudo-code example would
be:

while (...){
if (...) {
goto foo;
} else if (...) {
goto bar;
}
}

foo: { }
bar: { }
Sure, this is a better example of a goto, but JavaScript has not the
goto statement:

alert(goto = 1);

There's just the label, which is similar to a goto, but just works
together with break and continue.
But you can achieve the same result without using goto.
Sure :)
goto is long dead. If you want to support it's revival, present a
scenario where it is required, or where it is significantly more
efficient than existing methods.


One day you'll need to exit from a two nested loop, in this day you'll
see that a label is useful for something.

I've used the label something around two times, sure I could avoid it,
but it would require extra checking in the inner loop, in this specific
situation I'm all for the labels ;]
--
Now with alcohol <URL:http://youtube.com/watch?v=lnQTZxq xc10> =X
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
13311
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this wrong????? Function x select case z
0
7359
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7598
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7757
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7360
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7699
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5895
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5288
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3400
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
651
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.