PHP 編碼規范(14)

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;
}

隻要可以描述清楚各分支之間的關系,在哪裡寫註釋均可

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *