14. Understanding of loops

/*
Loop: that is, repetition. When certain statements are to be executed multiple times,
these statements will be placed in the curly brackets of the loop.

Loop body: is the collection of all statements within the loop curly braces.

The number of loops is often defined by an integer variable to control, called a loop variable.

Three necessary expressions of loop variables:
1. Initial value, which is an assignment statement, such as: x=1
2. Final limit, is a relationship or a relationship plus a logical expression, such as: x<=100
3. Step size, is a Compound assignment statement (will change the value of the loop variable), such as: x++, or

how the three expressions of the x+=2 loop variable should be combined:
1. If the initial value is less than the final limit, then the relational expression should be less than or
less than or equal to , the step size is += or ++
2. The initial value is greater than the terminal limit, then, the relational expression should be greater than or
greater than or equal to, and the step size is -= or --

When the loop terminal limit is false, the loop ends, and the loop variable The value is "greater than the limit" or "less than the limit"

The three expressions of the for loop variable and the execution order of the loop body:
1. Initial value
2. Final limit (execute the loop body when it is true, and end the loop when it is false (that is, after the closing curly bracket of the loop))
3. Loop body
4 .step size (will return to the end limit later, to judge true and false)
*/
#include "stdio.h"
void main()
{
int i;
int sum=0;

for(i=1;i<=100;i+ =5)
{
printf(" * ");
sum++;
if(sum%10==0)
printf("\n");
}
printf("The loop ends when the limit is false\n");
printf( "When the deadline is false, the loop variable is: %d\n",i);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325831973&siteId=291194637