In C ++ programming languages, many application methods are the same as those in C. However, as an upgraded version, there are many differences. For example, in the application of C ++ loop statements. Here we will introduce the concepts of C ++ loop statements in detail.
- Analysis of C ++ formatted string-related applications
- How to Implement C ++ print address information
- Detailed description of how C ++ generates random numbers
- Practical application skills of C ++ linked list operations
- A Brief Introduction to the C ++ Operating Mechanism
The commonly used C ++ loop statements are mainly if/while/for, where if and for are more frequently used.
We can divide the components of the C ++ loop statement into the following four parts:
<1> initialize the cyclic variable, that is, define the cyclic variable. It is a non-essential element of a loop statement and can be replaced by other Defined variables.
<2> when the cyclic condition is initialized, the final result of the cyclic condition is a number.
<3> change the value of the Loop Variable/condition.
<4> define the actual purpose of a loop
The for statement can be interpreted:
- for ( <1>; <2>; <3>; ) <4>
The if statement is interpreted:
- <1>;
- if <2>;
- {
- <4>;<3>
- }
- else
- {
- <4>;<3>
- }
The while statement is interpreted:
- <1> ;
- while( <2> )
- {
- < 4 >;< 3 >
- }
Similarly, the do while statement can be interpreted
- <1> ;
- do <4>;<3> while <2>
In summary, when writing a loop statement, you only need to complete the C ++ loop statement according to the attributes of each element. This memory method can help us to remember the rules of C ++ statements more quickly and reasonably. Of course, it can also be applied to all statements in memory C ++.