+ 1

Can a function break a while, do while or for?

30th Jul 2018, 4:04 PM
ForasterXD
ForasterXD - avatar
2 Respostas
+ 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.
30th Jul 2018, 4:28 PM
Babak
Babak - avatar
0
check out goto too.
30th Jul 2018, 6:42 PM
Bebida Roja
Bebida Roja - avatar