_ _ C language process control loop notes

cycle

for

1. Format

  for(1;2;3)

  {

       Statement A;

       Statement B;

  }

2. The execution flow ( in an example to illustrate, a number representative of statement )

#include<stdio.h>

 

int  main(void)

{

         int  i,sum;

         sum=0;

       

          for(i=1;i<=3;++i)

          {

                   ④sum=sum+i;

          }

         ⑤ printf("%d",sum);

          

          return  0;

}

In for performing sequential loop:

⑴ first execution ①, then execute ②. ② If true, execute ④, the last execution ③. One end of the loop.

⑵ first execution ② ( second cycle does not execute ① ) , then perform ②. ② If true, execute ④, the last execution ③. The second cycle ends.

...... until ② not true, the loop ends. Continue ⑤.

3. The finite nature

There must have poor circulation, can not infinite loop

4. The scope of the problem

for default only a statement control, controlling the plurality of braces required ( and if the same )

The mandatory data type conversion

① format : ( data type ) ( expression \ may also be a certain amount )

② For example :

// The value of the expression ( floating-point type ) cast to integer

float  i;

(int) (i*0.9);

// The integer variable cast to float

 int   i ;

 (float) (i);

③ function

The value of the expression cast preceding the data type

6. Number of test skills

① not to think about the purpose of the program, as the computers themselves, try to go step by step

Do not skip steps ②

③ write neatly, logically

7. float existence of problems caused by wrong

① reason

float and fouble can not guarantee exactly a storage value ( not all values can not be stored accurately, but can not guarantee that each of accurate memory )

For example ②

There is a floating-point number x , how to determine the x value is equal to zero

 IF (X - 0.000001 absolute <= 0.000001)

      Zero

 else

      It is not equal to zero

② Note

Update cycle ( from plus or minus from ) the floating point variable is not defined, since the float is a non-accurate storage

7.for and if nested exercises

Note that the definition of variables, generally by sum expressed and, by cnt indicates the number

8. plurality for nested heavy and difficult process []

( For convenience represented in this figure represents the expression, called 1 , 2 , 3 where the cycle of a cycle, said 4 , 5 , 6 where the circulation of small cycles )

  for(1;2;3)

          for(4;5;6)

          Statement A;

  Statement B;

The order of execution :

first implementation of 1 , then execute 2 , if true, then perform 4 ( small cycles start )

implementation of End 4 , the execution 5 , if it is set up to execute a statement A , and then perform 6 ...... until 2 does not hold, exit

After exiting the implementation of small cycles 3 , then execute 2 , if established will continue into the second cycle ( steps above, proceed to quit again after minor cycle 3) ...... until 2 does not hold, quit big loop, the loop ends, the statement is executed B

 

while

1. Format

  while ( expression )

       Statements ;

2. The order of execution

  First determine the expression that if true, the statement is executed. Then continue to determine the expression ... until the expression is not satisfied, exit the loop

3.for and while comparisons

for and while interchangeable, but for logical more

for(1;2;3)

{

    A;

}

Equivalent to

1;

while(2)

{

    A;

    3;

}

 

do......while

1. Format

  do

  {

     Statements ;

  } While ( expression );

2. Process

Execute the statement

determine the expression, if the establishment continues to execute the statement, does not hold exit the loop ( regardless of whether an expression established statements are executed at least once )

3. the while and for comparison

while ...... ...... do not equivalent to a while or for . Because if the expression is not true, the while and for not executing the statement, but do ...... while to be performed once

Guess you like

Origin www.cnblogs.com/qinenxi/p/10994982.html