How to stop void method (return in void method)

This is quick blog post about stopping executing void method. So, how to stop executing void return type method? We just need to use ‘return’ statement itself, for example:

public static void sum(int a, int b)
    if (a == 0) return;

If we pass 0 as first argument then we won’t get print from next line.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: