School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,492 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,847 people online right now. Registration is fast and FREE... Join Now!




looking for "goto"

 

looking for "goto", is there a "goto" in javascript?

sblund

24 Jun, 2009 - 12:14 PM
Post #1

New D.I.C Head
*

Joined: 30 Oct, 2008
Posts: 11



Thanked: 1 times
My Contributions
I've got a prompt in my java script, and I would like clicking "cancel" (which returns "null") to close the entire script. I'm thinking that the variable could be tested for the null value with an "if" statement imediately folowing the prompt and the associated action could either terminate the script or "goto" the end....maybe screwy, but looking for SOMETHING!
CODE
var rwdia = prompt("Enter rear wheel diameter-ex. 27","inches");
if (rwdia="") .......


User is offlineProfile CardPM
+Quote Post


Smurphy

RE: Looking For "goto"

24 Jun, 2009 - 12:28 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Jul, 2008
Posts: 251



Thanked: 7 times
Dream Kudos: 25
My Contributions
You can do that yes. I would not use goto. Many programmers hate the goto statement since it very easily will make your code very unreadable. Try the null statement.
User is offlineProfile CardPM
+Quote Post

sblund

RE: Looking For "goto"

24 Jun, 2009 - 12:32 PM
Post #3

New D.I.C Head
*

Joined: 30 Oct, 2008
Posts: 11



Thanked: 1 times
My Contributions
Ok, I don't really mind the goto (here the code is too short to get too confused) but how would I use the "null statement" here?

This post has been edited by sblund: 24 Jun, 2009 - 12:36 PM
User is offlineProfile CardPM
+Quote Post

moopet

RE: Looking For "goto"

24 Jun, 2009 - 12:42 PM
Post #4

D.I.C Regular
***

Joined: 2 Apr, 2009
Posts: 342



Thanked: 32 times
My Contributions
QUOTE(sblund @ 24 Jun, 2009 - 07:14 PM) *

I've got a prompt in my java script, and I would like clicking "cancel" (which returns "null") to close the entire script. I'm thinking that the variable could be tested for the null value with an "if" statement imediately folowing the prompt and the associated action could either terminate the script or "goto" the end....maybe screwy, but looking for SOMETHING!
CODE
var rwdia = prompt("Enter rear wheel diameter-ex. 27","inches");
if (rwdia="") .......



Put your code in a function. Then you can return when finished:
CODE

function doSexyThing()
{
    var rwdia = prompt("Enter rear wheel diameter-ex. 27","inches");
    if (rwdia="")
    {
        return;
    }

    alert("this thing is very sexy");
}

// call it
doSexyThing();

User is offlineProfile CardPM
+Quote Post

sblund

RE: Looking For "goto"

24 Jun, 2009 - 12:49 PM
Post #5

New D.I.C Head
*

Joined: 30 Oct, 2008
Posts: 11



Thanked: 1 times
My Contributions
Oh, you are soooo right!

Hey, thanks a bunch....just the thump on the head that I needed!!
sbl
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:34AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month