1.3. A Word About Comments
It is usually best to place a comment block above the code it explains.
Comment Pairs Do Not Nest(嵌套)
When commenting out a large section of a program, it can seem easiest to put a comment pair around a region that you want to omit temporarily. The trouble is that if that code already has a comment pair, then the newly inserted comment will terminate prematurely. A better way to temporarily ignore a section of code is to use your editor to insert single-line comment at the beginning of each line of code you want to ignore. That way, you need not worry about whether the code you are commenting out already contains a comment pair.
1.4. Control Structures1.4.1. The while Statement1.4.2. The for Statement
#include <iostream>
1、Create val and initialize it to 1. 2、Test whether val is less than or equal to 10. 3、If val is less than or equal to 10, execute the for body, which adds val to sum. If val is not less than or equal to 10, then break out of the loop and continue execution with the first statement following the for body. 4、Increment val. 5、Repeat the test in step 2, continuing with the remaining steps as long as the condition is true.
When we exit the for loop, the variable val is no longer accessible. It is not possible to use val after this loop terminates. However, not all compilers enforce this requirement. |
The most common kinds of errors a compiler will detect:
Syntax errors.(语法错误)
Type errors.
Declaration errors.