Hi! Every I need your help.
How can I terminate a function?
Hi! Every I need your help.
How can I terminate a function?
Use a return statement.
If you are having an infinite loop inside,it may also cause a never ending function. Use "break" in that case.
Return will work in the case of an infinite loop, if it is inside the body loop of course.
When the code of the body of the function reaches an the keyword, it will terminate, no matter what.
break keyword, will stop the loop and will transfer the flow of your code after the body of the loop.
Of course, you can use a "return", even if your function is of return value void.
Example.
Code:void foo(int a) { if(a < 5) return; ... }
Code - functions and small libraries I use
It’s 2014 and I still use printf() for debugging.
"Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson
Thanks! )