+ 1
Can a function break a while, do while or for?
2 Respuestas
+ 5
Definitely!
If the function has a non-void return type (and possibly accepts arguments to do some meaningful operations), using an if statement inside the body of the loop and check the return value from the function against a specific value will do the job.
●●Big picture●●
non-void return type loopBreaker(some params) {
// do some stuff here
return some value based on the result of stuff
}
//...
LOOP (...) {
// do some stuff here
if (loopBreaker(call by some args) == VALUE)
break;
}
Note that == is just an example to test the equality of the two guys.
0
check out goto too.