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
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.
+ 4
You may find answer in :-
1) https://www.google.com/search?q=how+to+use+goto+in+javaScript&rlz=1C9BKJA_enUS705US705&oq=how+to+use+goto+in+javaScript&aqs=chrome..69i57j0l2.30708j0j4&hl=en-US&sourceid=chrome-mobile&ie=UTF-8
2) https://www.tutorialspoint.com/How-can-I-use-goto-statement-in-JavaScript
3) https://www.codespeedy.com/how-to-use-goto-statement-in-javascript/
+ 2
Use functions
https://www.sololearn.com/learn/JavaScript/1145/
+ 2
Mehzie
See an example
https://code.sololearn.com/WSUQQ5hV9LFd/?ref=app
+ 1
Ore Adeleye thanks so much for this, it was a great help
+ 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.
+ 1
var a = 0;
[lbl] beginning:
console.log("Demo Text!");
a++;
if(i < 424) goto beginning;
0
Ore Adeleye thank you so much