Basic concepts of C ++ cyclic statements

Source: Internet
Author: User

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:

 
 
  1. for ( <1>; <2>; <3>; ) <4> 

The if statement is interpreted:

 
 
  1. <1>;  
  2. if <2>;  
  3. {  
  4. <4>;<3> 
  5. }  
  6. else  
  7. {   
  8. <4>;<3> 

The while statement is interpreted:

 
 
  1. <1> ;  
  2. while( <2> )  
  3. {  
  4. < 4 >;< 3 > 

Similarly, the do while statement can be interpreted

 
 
  1. <1> ;  
  2. 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 ++.

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.