0

How to use "goto" in Javascript

Please, how can I make use of goto in Javascript, how do I create labels and how do I goto the labels created. Imagine a case where user inputs a wrong password and my code asks the user if they wish to try again, if answer is true, how do I take the user back to the beginning to input password again. Thanks

10th May 2020, 8:12 PM
Mehzie
Mehzie - avatar
8 Respostas
+ 4
There is not goto in JS. As Ore Adeleye said you should use a function to mimic the goto functionality. This is how you create labels in JS 👇 outer: for(;;;){ .... inner: for(;;;){ if(condition){ break outer; } } Labels are used with break and continue keywords only and other approaches are usually preferred.
10th May 2020, 9:45 PM
Kevin ★
10th May 2020, 8:22 PM
Ore
Ore - avatar
11th May 2020, 11:10 AM
Ore
Ore - avatar
+ 1
Ore Adeleye thanks so much for this, it was a great help
10th May 2020, 8:24 PM
Mehzie
Mehzie - avatar
+ 1
Kevin Star thanks, can you write a full code so I can better understand how to make use of the keywords. The function keyword actually did a pretty job, but am not yet very conversant with it, so using it was a bit sloppy.
11th May 2020, 10:02 AM
Mehzie
Mehzie - avatar
+ 1
var a = 0; [lbl] beginning: console.log("Demo Text!"); a++; if(i < 424) goto beginning;
12th May 2020, 5:47 PM
Satyam Patel
Satyam Patel - avatar
0
Ore Adeleye thank you so much
11th May 2020, 11:13 AM
Mehzie
Mehzie - avatar