10-16c#for ... Loop statements (2)

Source: Internet
Author: User

For .... Looping statements

Format: for (initial condition; cyclic condition; state change)

Circulation body;

First, pre-school assignments: print isosceles right triangle

The first method is to use a start to learn from the top down to execute the console program, with a For loop statement execution, there is only one loop.

The second approach is to use a for nested loop statement, which is a small loop consisting of one or more for statements nested within a for loop.

(Note: In the nested loop inside the error is easy to make: after the large loop condition is executed once, the cursor continues from the top down the following small loop, as long as the conditions within the small loop in line with, it will continue to execute in the inside, only do not meet the cycle conditions of the small loop, the cursor will automatically jump out (break) Return to change the state of the large loop and execute the cycle condition. ) Personal Understanding ...

This is for ... The running process of nested loops is summed up briefly:

Cycle nesting small loops

Cycle, turn around, turn around in a small circle.

Cycle turn around, small cycle turn round, the innermost cycle of a small cycle of a circle * It itself turns a circle

The following is an example of printing different isosceles right triangle and diamonds (top half, lower half) for ... Nested loops:

To print a complete diamond:

( Note: Console.Write ("");) the white space inside the double quotation marks, although nothing is entered, but the equivalent of two characters in position, because we know that an English letter occupies a character, and usually symbols, Chinese characters are two characters, so remember this, is not omitted In addition, although the diamond uses for ... Loop statements, be sure to master the sequence of execution of nested loop statements, do not wrap yourself in.

Exercise 1: classic example: Rabbit born rabbit problem, first of all to find out the rules list, find the rabbit, rabbit

The relationship between the hare and the rabbit is then written in the loop statement execution.

1

TD valign= "Top" width= ">

into a rabbit

0

0

1

1

2

3

5

8

Bunny

0

0

1

1

2

3

5

Young Rabbits

1

0

1

1

2

3

5

8

The first 1 months

The first 2 months

The first 3 months

The first 4 months

The first 5 months

The first 6 months

The first 7 months

The first 8 months

Exercises 2:

The two most important methods for a For loop are:

Second, iterative method

The simplest understanding is that as long as the conditional infinite loop is satisfied, the loop jumps out once it is not satisfied. Is the above mentioned execution of a for ... Loop statement.

Iii. the method of poor lifting

three loops of nesting : Cycle loops in the loop, until the loop is complete, all the possible results are listed, even if the result is not the desired results will be listed, we want to extract the results.

10-16c#for ... Loop statements (2)

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.