C-language dummies (1): nested loops-program structure, dummies

Source: Internet
Author: User

C-language dummies (1): nested loops-program structure, dummies

Loop statement nesting a loop structure can contain another loop, called loop nesting, or multiple loops. The nested loop is a double loop. The outer loop is called an external loop, and the inner loop is called an internal loop. --------- I don't know where the basic concepts come from

  

  This is the first blog of the baby. I will not ask for more popularity or praise. I will summarize the content of the day every day. If there are obvious or minor details errors in this article, nothing will happen, please leave a message to correct it ~

   

1. nested loop

  The name of the nested loop is in the while. do... while, for three common loop structures within the scope of the use of three cycle structures again use a problem-solving mode, double nesting and multiple nested thinking and two-dimensional array multi-dimensional array

The concept is similar. If you think about it,

# Include <stdio. h> int main (int argc, const char * argv []) {for (int I = 1; I <= 10; I ++) // outer loop. print 1 line for one loop. {for (int j = 0; j <10; j ++) {for (int k = 0; k <= 10; k ++) {.....}}}

 

The difference between int [10] [10] [10] and int [10] is only the number of storage cycles and a storage element.

As a matter of fact (because of the lack of listening in class), when we see nested loops in the exam questions... I thought this Nima was so simple that I had to create an alias... (There are too many rankings in the computing industry)

  Ii. Example: 9-9 multiplication table

   First, sort out the ideas:

1. Nine tables have a total of nine rows. Therefore, there is no doubt that a circular loop should be written nine times and one row should be printed each time.

2. Because the 9-9 Table has nine columns, and because the number of sub-columns in each row is exactly the same as the row number and the maximum number of row numbers is 9, the nested loop stop condition is: j <= I;

3. Refer to the print template row number * column number = structure I * j = result;

# Include <stdio. h> int main (int argc, const char * argv []) {for (int I = 1; I <= 9; I ++) // outer loop, print a row once in a loop. {for (int j = 1; j <= I; j ++) {// '\ t' represents one Tab key. align printf ("% d * % d = % d \ t", j, I, I * j);} printf ("\ n");} return 0 ;}

 

  Iii. code structure Summary

Generally, there are three career options for the start of the new account: novice: sequential structure, intermediate: cyclic structure, advanced: branch structure. The execution modes of these three structures without function calls are as follows:

1. Ordered Structure

The code is executed from the top row to the next row, and each row can be executed. This is called the sequential structure.

2. Branch Structure

The structure used by the if and swich-case functions is called the branch structure. They allow the C language code to add more detailed branches and use the if, if .. else, if .. else if .. (else), and the break and default of swich

It makes the logic of the Code closer. For the two of them, we are also called the judgment structure and selection structure.

3. Loop Structure

The same piece of code is repeatedly executed for a specified number of times.

While, do... while, for is the main loop structure

    By the way, there are three common methods of endless loops: while (1), do... while (1), (;;),

The sequence and branch structure do not generate code rollback, so the loop structure should be used properly when repetition is required.

  

Related Article

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.