Questions about "for" loop
How does the for loop respond too "continue", "break" and "return" ?
If i want to stop looping and jump to the code after the loop after some condition is satisfied which one should i use. Example: PHP Code:
Similarly if i want to just return the value and stop executing the ENTIRE function then ? |
Re: Questions about "for" loop
return will stop the entire function "myfunc"
continue will stop the current iteration of the loop, and begin the next one break will stop the loop immediately, and continue on with the rest of the function. |
Re: Questions about "for" loop
Ok thanks man.
|
Re: Questions about "for" loop
Is returning in loop a good way? I have always broke it, then return.
|
Re: Questions about "for" loop
Quote:
Code:
I don't see a problem in using "return" in a loop, if you don't want to continue with the function, if the loop reach something, return is just fine. This all depends on what you need. Code:
By using break the block of code outside the loop will still execute. If you will use return it won't. |
Re: Questions about "for" loop
should i "break" somewhere the loop here ?. ( this is blocking some items for others after 1 user bought one time in 1 map )
PHP Code:
|
Re: Questions about "for" loop
Why you need it? I don't see that it can be useful in your situation. ;)
|
Re: Questions about "for" loop
Quote:
|
Re: Questions about "for" loop
Its fine to use return in loop. Other ways we could not use it there if it would not be fine.
|
Re: Questions about "for" loop
continue - skip to the next step.
break - breaks the loop. return - breaks the loop and blocking from the rest of the fuction calling |
All times are GMT -4. The time now is 18:14. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.