ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
your MY_OWN_CODE will never be reached since you execute an exit at the end of the for loop. That means that the program will stop executing (with only one iteration).
The prompt function is used strangely. First, it should have an "exit" since it will stop the program right after sending the HTTP headers (why would you want to stop after that?). Secondly, you should call that function only once, since you cant send HTTP Headers after any output. So it should be called before the for loop, not at the end.
Another observation is that if you call "return" inside your for loop, you will also never reach the MY_OWN_CODE since it will stop the execution of the script (perhaps you meant to put a break?).
Hi naihe,
I think that your loop is not necesary. Why do you want to do 3 times the same thing? If you want to give the user 3 tries, I think that you should take as a guide what senyahnoj has posted just above. Your web programms cannot interact directly with the user, so you cant ask the user anything in a loop. You have to send him an HTML page, wait for the user to submit, and again and again. So your loop disappears and is just execute as the user submits the form or whatever.
Perhaps you could explain a little bit more what you want to accomplish with this loop.
Another observation is that if you call "return" inside your for loop, you will also never reach the MY_OWN_CODE since it will stop the execution of the script (perhaps you meant to put a break?).
Might also mess up the stack and lead to mysterious bugs at a later point in the script. Best to set a flag, then break out of the loop, then test the flag to determine whether/what to return.
Hi naihe,
I think that your loop is not necesary. Why do you want to do 3 times the same thing? If you want to give the user 3 tries, I think that you should take as a guide what senyahnoj has posted just above. Your web programms cannot interact directly with the user, so you cant ask the user anything in a loop. You have to send him an HTML page, wait for the user to submit, and again and again. So your loop disappears and is just execute as the user submits the form or whatever.
Perhaps you could explain a little bit more what you want to accomplish with this loop.
Cheers!
Thank you very much!
I see, now. the three times tries was send by the user's explorer, not by the server.
The loop in this script is never working.
Yes the loop is not really cool
I think you should go with senyahnoj sugestion and use a COOKIE (or SESSION or whatever) to keep track of the attempts. Plus, you'll probably learn something new
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.