Home >Backend Development >PHP Tutorial >PHP coding standards (14)_PHP tutorial

PHP coding standards (14)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:20:26825browse

6 if and else statements

if-else statement should have the following format:


if (condition){ /* Conditions for operation */
 statements;
}

if (condition) {/*Conditions for performing operations. */
 statements;
} else {/*Conditions for performing operations*/
 statements;
}

if (condition) {/*Conditions for performing operations*/
 statements;
} else if (condition) {/*Conditions for performing operations*/
 statements;
} else{ /*Conditions for operation*/
 statements;
}

Note: if statements are always enclosed in "{" and "}" to avoid using the following error-prone formats:


if (condition) //Avoid this way of writing, he ignores "{}"
 statement;

The comment format can also be written in the following way

if (condition) {
/*Conditions for operation*/
 statements;
} else {
/*Conditions for operation*/
 statements;
}

As long as you can clearly describe the relationship between the branches, you can write comments anywhere


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532590.htmlTechArticle6 if and else statements if-else statements should have the following format: if (condition){ /* for operation Conditions*/ statements; } if (condition) {/*Conditions for operation. */ statements; } else...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn