How would I exit a function or procedure? I'm new to this :)
Printable View
How would I exit a function or procedure? I'm new to this :)
Use the return keyword. One thing to note is that you must return a value of the same type as the function's definition:
As you can see from the second example, no other statements are executed.Code:int myfunc(int i) {
return i;
}
bool anotherfunc(int i) {
if(i > 5) {
return true;
} else {
return false;
}
If you use a void, then you do not need to return anything.
It's impossible to return the wrong type because the compiler will whinge at you.