vmars316 Posted October 18, 2014 Share Posted October 18, 2014 Hello & Thanks; The following doesn't work, pls, how come ? <script type="text/javascript"> function myFunction() { var i = 0; start: while(i < 3) { alert("alert box #1"); alert("alert box #2"); i++; if(i < 3) continue start; break; } </script> Thanks..vm Link to comment Share on other sites More sharing options...
niche Posted October 18, 2014 Share Posted October 18, 2014 (edited) for starters, look at your curly brackets Also, check out the the if tutorial: http://www.w3schools.com/js/js_if_else.asp EDIT: Do you mean continue instead of start? Edited October 18, 2014 by niche Link to comment Share on other sites More sharing options...
davej Posted October 18, 2014 Share Posted October 18, 2014 If you want to write horrible code then use Javascript labels. Of course that is just my biased opinion. Link to comment Share on other sites More sharing options...
vmars316 Posted October 18, 2014 Author Share Posted October 18, 2014 for starters, look at your curly brackets Also, check out the the if tutorial: Do you mean continue instead of start? Thanks, Ok, fixed the curly brackets . I can't see the if error. I think I mean continue, so flow will go up to start. But still no go. <script type="text/javascript"> function myFunction() { var i = 0; start: while (i < 3) { alert("alert box #1"); alert("alert box #2"); i++; if (i < 3) continue start; break; } } </script> Thanks..vm Link to comment Share on other sites More sharing options...
davej Posted October 18, 2014 Share Posted October 18, 2014 Maybe you should describe in words what you actually want or expect this code to do. The whole idea of labels is to allow you to exit a particular loop in a nested set of loops or to continue execution at the top of a particular loop. For a single loop such as your code there is no need for a label. Link to comment Share on other sites More sharing options...
vmars316 Posted October 18, 2014 Author Share Posted October 18, 2014 (edited) expect this code to do. I just want to create a looping structure. Using only js. Eventually, alert 1 & 2 will be, or point to functions. Edited October 18, 2014 by vmars316 Link to comment Share on other sites More sharing options...
Ingolme Posted October 18, 2014 Share Posted October 18, 2014 The code is working exactly as it should when I test it. What are you expecting it to do? Link to comment Share on other sites More sharing options...
vmars316 Posted October 18, 2014 Author Share Posted October 18, 2014 Ya, I even changed it to : <script type="text/javascript"> function myFunction() { var i = 0; while (i < 3) { alert("alert box #1"); alert("alert box #2"); i++; } } </script> And it still doesn't work. I'll try a reboot. Link to comment Share on other sites More sharing options...
Ingolme Posted October 19, 2014 Share Posted October 19, 2014 What do you mean by "doesn't work"? Remember to call the function somewhere with myFunction(); Link to comment Share on other sites More sharing options...
vmars316 Posted October 20, 2014 Author Share Posted October 20, 2014 What do you mean by "doesn't work"? Remember to call the function somewhere with myFunction(); "doesnt work = no 'alert'". " myFunction(); ". Sorry to say, I didnt realize that. Thanks a lot. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now