Breaking out of function in c++ -
how leave function in middle? have condition leaving function, dont know how leave.
ex:
void a(int &num){ if (num > 100){ // leave function } num += a(num + 1); } i want end recursion, , have keep function void
void a(int &num){ if (num > 100){ return; } num += a(num + 1); } as pointed in comments martin york, jumped on answer without considering every aspect of question, , apologize. want :
int a(int num) { if (num > 100) return num; return num + a(num + 1); }
Comments
Post a Comment