18 C # executes the for loop,

Source: Internet
Author: User

18 C # executes the for loop,

 

In this exercise, we will introduce another important loop statement in C #, for loop.

 

For (expression 1; expression 2; expression 3)

{

Loop body

}

 

Expression 1: Generally, it is a value expression that assigns an initial value to the control variable;

 

Expression 2: A logical expression and a loop control condition. When the condition is true, statements in the loop body are cyclically executed.

 

Expression 3: Generally, it is a value expression that increments or reduces the number of control variables.

 

It seems abstract. Through actual examples, you can easily understand the for loop.

 

You create a project. The solution name is Sloution18, the project name is Exercise18, and the project type is console program. Click Program. cs. Add the code to it.

 

 

Briefly explain this program.

1. 14th rows are the core of the for loop. I is the control variable. Int I = 0; assign an initial value to control variable I;

2. I <= 10; it is a condition for loop control. When I <10, the statement in braces is executed;

3. I ++ controls variable increments. 1.

4. 17th rows are accumulated from 1 to 10. Computing 1 + 2 + 3 + 4 +... + 10.

 

Running result

 

Exercise

1. Read this code and add comments to important statements.

2. If you change the 14th lines of code to for (int I = 0; I <= 10;), what is the result of running the program?

3. What will happen if you change the code in line 3 to for (int I = 0; I ++?

4. modify the code so that the program can output the I value from 0 to 20 to the dos window, and calculate the accumulated result from 0 to 20.

 

 

 

 

Pay-as-you-go answers to questions C # encountered during the course of getting started.

Zero-basic learning C # beginners, most problems can be solved through self-study or the Internet.

HoweverThere are still some problems that are not so easy to solve and become a stumbling block to your learning. In the end, it may even cause you to lose your learning experience. Generally, when you get started with C # programming, you will encounter more than 20 to 30 problems that you cannot easily solve.

What do you need most at this time?

Yes! A professional teacher will help you!

If you have any questions during this course, you can ask the author for help via qq or email.

Only 30 RMBYou can get three professional answers from the author of this tutorial. So you only need less than 300 yuan to successfully complete the C # entry, and then open the door to the software industry.

 

The payment method is very simple:

Scan the following QR code. Leave your QQ number or email address in the payment message.

 

Education is not cheap, but reliable! Truly smart people know how to spend money to make professional people serve themselves and improve their efficiency.

 

Instructor qq: 2040227296

Instructor email: 2040227296@qq.com

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.