I have some code that I absolutely must implement using goto. For example, I want to write a program like this:
start:
alert("RINSE");
alert("LATHER");
repeat: goto start
Is there a way to do that in Javascript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Absolutely! There is a project called Summer of Goto that allows you use JavaScript at its fullest potential and will revolutionize the way you can write your code.
This JavaScript preprocessing tool allows you to create a label and then goto it using this syntax:
For example, the example in the question can be written as follows:
Note that you are not just limited to simple trivial programs like an endless
LATHERRINSErepeat cycle—the possibilities afforded bygotoare endless and you can even make aHello, world!message to the JavaScript console 538 times, like this:You can read more about how goto is implemented, but basically, it does some JavaScript preprocessing that takes advantage of the fact that you can simulate a goto with a labelled
whileloop. So, when you write the "Hello, world!" program above, it gets translated to something like this:There are some limitations to this preprocessing process, because while loops cannot stretch across multiple functions or blocks. That’s not a big deal, though—I’m sure the benefits of being able to take advantage of
gotoin JavaScript will absolutely overwhelm you.All above link that lead to goto.js library is ALL DEAD, here is links needed:
goto.js (uncompressed) — parseScripts.js (uncompressed)
From Goto.js: