What is the granularity of branching?

This is a pretty dumb question, and googling gave me conflicting answers.

In a if statement, say if(a < b && c > d), would this be considered 1 or 2 branches in java? I’m mainly confused on if the statement is considered a branch, or if each compare expression are branches. I understand only one gets evaluated at a time leading me to believe there are 2 branches, but I would like to be reassured by someone.

Yes, it is two branches, as the ‘&&’ is short-circuiting, leading to it being equivalent to:


if(a < b)
    if(c > d)
        ...

With only a ‘&’, it would be one branch.

Of course the optimizer might do something different in either of these situations, like a conditional move.

If I chained expressions using &, then would (a < b & c > d) be a single branch?

You can’t say. Especially without seeing the rest of the code. Don’t worry about branches.