6 if與else語句 if-else語句應該具有如下格式: if (condition){ /* 進行操作的條件 */ statements; }
if (condition) {/*進行操作的條件. */ statements; } else {/*進行操作的條件*/ statements; } if (condition) {/*進行操作的條件*/ statements; } else if (condition) {/*進行操作的條件 */ statements; } else{/*進行操作的條件*/ statements; }
注意:if語句總是用"{"和"}"括起來,避免使用如下容易引起錯誤的格式: if (condition) //避免這種寫法,他忽略了“{}” statement;
注釋格式也可以像下面的這種方式寫
if (condition) { /*進行操作的條件*/ statements; } else { /*進行操作的條件*/ statements; } 只要可以描述清楚各分支之間的關系,在哪里寫注釋均可
|