The basic structure of C language--cyclic structure

Source: Internet
Author: User

Today, the president of our computer Association told me to give my primary school brother Elementary School girls A C-language introduction, their teacher has already told the previous blog we wrote, I intend to tell them the basic structure of C language-cycle, judgment, branch.
Today we will focus on the circular structure.
The cyclic structure is divided into three kinds, namely for, while, Dowhile;
We first say the first: for loop. The format of his code is:

for(判断的数值初始化;判断条件;改变判断数值大小){    循环语句块;}

For example, let's take an example of the output 1~10 number:

#include<stdio.h>int main(void){    int i;    for(i=1;i<=10;i++){        printf("%d\t",i);    }}

The result of the program operation is:

1    2    3    4    5    6    7    8    9    10

That is, the first cycle when the I=1 output and run the i=i+1 operation, the second cycle, until i>11.
Let's talk about the use of the while loop:

 while(循环判断条件){        循环语句块;    }

We also use the above example to write the program:

#include<stdio.h>int main(void){    int i=1;    while(i<=10){        printf("%d\t",i);        i++;    }}

The result of the program operation remains:

1    2    3    4    5    6    7    8    9    10

His running process and for similar, no longer explained too much.
Now, let's say it's not the same as the two of them. Do-while Loops
First, let's take a look at his structure.

#include<stdio.h>int main(void){    int i=1;    do{        printf("%d\t",i);        i++;    }while(i<=10);}

His results and the above, no longer tell everyone his results, why we say that this cycle and the front of the loop is not the same, because the first two loops are first to judge the running program quickly, and Do-while cycle is the first to run the program quickly, then judge, see if he meets the conditions.
This is the whole loop structure, very simple, but generally they are used in nesting. I need you to delve into this.

The basic structure of C language--cyclic structure

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.