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

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -