In an if statement, what are an “if clause” and a “then clause”

code-completecontrol-structuresif statementterminology

I am a bit confused about the nomenclature for the parts of an if statement. Consider the following example:

1:  if condition then
2:      statement_1;
3:  else
4:      statement_2;
5:  end if;

What is the "if clause" in this statement? Here are a few possibilities:

  • Is it lines #1 and #2?
  • Is it line #1?
  • Is it line #2?
  • Is is the condition in line #1?

And in the same example, what would be the "then clause"?

  • Is it line #2?
  • Is it the then keyword, plus line #2?
  • Is it just a synonym for "if clause"?

My main reference is Code Complete 2nd Ed., but the author seems to use exclusively the term "if clause", with the meaning being lines #1 and #2 in this example.

Best Answer

The reason you hear about conditional "clauses" is because English has clauses. When you hear about conditional clauses in programming, what the person is speaking about is "that which embodies the condition."

So the if clause is

if condition then
    statement_1;

because that's the part that pertains to the if.

The else clause is

else
    statement_2;

because that's the part that pertains to the else.

Related Topic