Is “else if” a single keyword?

后端 未结 8 1971
忘了有多久
忘了有多久 2021-01-31 01:13

I am new to C++. I often see conditional statement like below:

if 
  statement_0;
else if
  statement_1;

Question:

Syntacticall

相关标签:
8条回答
  • 2021-01-31 01:38

    An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.

    When using if , else if , else statements there are few points to keep in mind.

    An if can have zero or one else's and it must come after any else if's.

    An if can have zero to many else if's and they must come before the else.

    Once an else if succeeds, none of he remaining else if's or else's will be tested.

    have a look if...else statement tutorial.

    0 讨论(0)
  • 2021-01-31 01:43

    You can see the scope by using curly braces:

    if(X) {
      statement_0;
    }
    else {
      if(Y) {
        statement_1;
      }  
    }
    

    And normally implemented with two distinct keywords, one is if and one is else.

    0 讨论(0)
提交回复
热议问题