How can I use goto in Javascript

0 votes

I have some code that I simply must use goto to implement. For instance, I'd want to build a programme that looks like this:

start:
alert("RINSE");
alert("LATHER");
repeat: goto start

Is it possible to achieve this with Javascript?

Jun 8, 2022 in Node-js by Vaani
• 7,070 points
4,391 views

1 answer to this question.

0 votes

This JavaScript preprocessing tool allows you to create a label and then goto it using this syntax:

[lbl] <label-name>
goto <label-name>

For example, the example in the question can be written as follows:

[lbl] start:
alert("LATHER");
alert("RINSE");
[lbl] repeat: goto start;

Note that you are not just limited to simple trivial programs like an endless LATHER RINSE repeat cycle—the possibilities afforded by goto are endless and you can even make a Hello, world! message to the JavaScript console 538 times, like this:

var i = 0;
[lbl] start:
console.log("Hello, world!");
i++;
if(i < 538) goto start;

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 while loop. So, when you write the "Hello, world!" program above, it gets translated to something like this:

var i = 0;
start: while(true) {
  console.log("Hello, world!");
  i++;
  if(i < 538) continue start;
  break;
}

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 goto in 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)

answered Jun 9, 2022 by Neha
• 9,020 points

Related Questions In Node-js

0 votes
1 answer

How can i get the extension of the image in node.js?

Hello @kar You can do the following to ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
2,090 views
0 votes
1 answer

How can I use an http proxy with node.js http.Client?

Hello @kartik, You can use request, I just found ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,840 points
10,548 views
0 votes
1 answer

How do I use HTML as the view engine in Express?

Hello @kartik, To make the render engine accept ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,840 points
10,095 views
0 votes
1 answer

How do I get the time of day in javascript/Node.js?

Hello @kartik, This function will return you the ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
1,171 views
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
729 views
0 votes
1 answer

Migrating proxy npm repo in nexus 3

I don't think you can achieve this ...READ MORE

answered Jun 22, 2018 in DevOps Tools by DareDev
• 6,890 points
1,518 views
+1 vote
1 answer

What is the difference between JavaScript and Java

This quote rightly explains that 2 totally ...READ MORE

answered Jun 29, 2018 in Java by Daisy
• 8,140 points
784 views
0 votes
1 answer

How can i export socket.io into other modules in nodejs?

Because app.js is usually the main initialization ...READ MORE

answered Jun 17, 2022 in Node-js by Neha
• 9,020 points
4,286 views
0 votes
1 answer

How to use pino-transport in nodejs for logs?

Ensure that you have a recent version ...READ MORE

answered Jun 9, 2022 in Node-js by Neha
• 9,020 points
5,221 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP