This is an empty statement. A single semicolon alone does not perform any operations.
In this context, this means that if the if condition if true, do nothing.
Without an else section, there is not much use in this code. If so, the question is whether the condition should be inverted and should contain only the non-empty part of if .
In this case, it is a simple conditional, so in style it is probably better to invert it, however, if the condition is more complex, it may be clearer to write this path. For example, this:
if ((a==1) && (b==2) && (c==3) && (d==4)) { ; } else { // do something useful }
May be clearer than this:
if (!((a==1) && (b==2) && (c==3) && (d==4))) { // do something useful }
Or that:
if ((a!=1) || (b!=2) || (c!=3) || (d!=4)) { // do something useful }
Best example from comments (thanks Ben):
if (not_found) { ; } else { // do something }
Versus:
if (!not_found) { // do something }
Which method to use largely depends on what exactly is compared, how many terms are there, how the terms and even the names of variables / functions are embedded.
Another example of when you can use this is that you have a set of if..else to check a range of values ββand you want to document in code that nothing should happen for a specific range:
if (a < 0) { process_negative(a); } else if (a >=0 && a < 10) { process_under_10(a); } else if (a >=10 && a < 20) { ;
If an empty if was omitted, the reader might wonder if something should have happened there, and the developer forgot about it. Including an empty if , he tells the reader: "Yes, I explained it, and nothing should happen in this case."
Some coding standards require that all possible results be explicitly incorporated into the code. Thus, code adhering to such a standard might look something like this.