上記の回答 [Dave Newton]を展開したいと思います。
単一の文しかない場合は、角括弧なしの構文を使用できます。だから、これは有効です。
コード:以下のコードで
if expression==true.
に実行されます上記、声明の中で
if (expression)
statement;
、それはまだ動作しますが、あなたが期待するものではありません。
コード:
if (expression)
statement1; // only this is inside of the if
statemen2; // this is outside your if statement
文2がoutsid扱われますあなたのif..else構造体をスローするif文の範囲のeです。 if文の中にはstatement1しかありません。あなたは複数のステートメントがあれば内で実行する場合は、(上述ポスターとして)ブラケットを使用します。
コード:
if (expression) {
statement1; // both of these will be executed if the expression is true
statement2;
}
をので、明らかに、
if (condition) {stuff; return;}
else otherStuff;
は自分のものを行います。
その他の参照:Braces are your friend
なし、ブロックが第一セミコロンまでです。 – Dave