c - How can I break out of a function -
i need check condition. if true, operation performed , need break out of function. if condition not satisfied proceeding normal operations in function continue.
the return
keyword used exit function.
if function has non-void
return type, expression of appropriate type must used return
provide return value:
/* returns 2 * abs(a), abs(a) denotes absolute value of a. */ int twice_positive(int a) { if(a < 0) return -2 * a; return 2 * a; }
some people consider "early return" long(er) functions evil stylistically , avoided; don't agree thought should mention it.
Comments
Post a Comment