Beginners: Learn to Master Dynamic Web PHP programming statements

Source: Internet
Author: User

1 Simple Statements

Each line contains at most one statement, for example:

$ARGV + +; Right to
$ARGC--; Right to
$ARGV + +; $ARGC--; of the wrong

2 Compound statements

A compound statement is a sequence of statements contained in curly braces, in the form of "{statement}". For example, the following paragraphs.

-The statements that are enclosed should be indented one level more than compound statements
-The opening brace "{" should be at the end of the line at the beginning of the compound statement, and the closing brace "}" should be on a separate line and aligned with the first line of the compound statement.
-curly braces can be used for all statements, including individual statements, as long as they are part of a if-else or for control structure. This makes it easy to add statements without having to worry about introducing bugs by forgetting braces

3 Return statement

A return statement with the returned value does not use parentheses "()" unless they somehow make the return value more visible. For example:

Return
return Mydisk.size ();
Return ($size $size: $defaultSize);

4 If and ELSE statements

The If-else statement should have the following format:

if (condition) {/* The conditions of operation * *
statements;
}
if (condition) {/* The condition under which the operation is made. * *
statements;
else {/* conditions to operate
statements;
}
if (condition) {/* The conditions of operation * *
statements;
The conditions for the operation of else if (condition) {/* * *
statements;
else{/* the conditions of operation * *
statements;
}

Note: If statements are always enclosed in "{" and "}", avoid the following error-prone formats:

if (condition)//Avoid this notation, he ignores "{}"
Statement

The annotation format can also be written as follows

if (condition) {
/* Conditions of Operation * *
statements;
} else {
/* Conditions of Operation * *
statements;
}

As long as you can describe the relationship between the branches, where to write comments can be

5 for statement

A For statement should have the following format:

for (initialization; condition update) {
statements;
}

An empty for statement (all work in initialization, conditional judgment, UPDATE clause completion) should have the following format:

for (initialization; condition; update);

When using commas in initialization or update clauses of a for statement, avoid using more than three variables, resulting in increased complexity. If necessary, separate statements can be used before the for loop (for initialization clauses) or at the end of the For loop (for UPDATE clauses).

6 While statement

A while statement should have the following format

while (condition) {
statements;
}

An empty while statement should have the following format:

while (condition);

7 Do...while Statement

A do-while statement should have the following format:

do {
statements;
while (condition);

8 Switch statements

A switch statement should have the following format:

Switch (condition) {
Case ABC:
/* Falls through * *
statements;
Case DEF:
statements;
Break
Case XYZ:
statements;
Break
Default
statements;
Break
}

Whenever a case goes down (because there is no break statement), you should usually add a comment at the location of the break statement. The example code above contains comments/* Falls through * *.

9 Try...catch Statement

A try-catch statement should have the following format:

try {
statements;
catch (Exceptionclass e) {
statements;
}

A Try-catch statement may also follow a finally statement, which is executed regardless of whether the try code block is executed successfully.

try {
statements;
catch (Exceptionclass e) {
statements;
finally {
statements;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.