17. Execute the while loop in C,

Source: Internet
Author: User

17. Execute the while loop in C,

 

There are three main methods for code execution in programming. (1) sequential execution, that is, one statement and one statement are executed in order; (2) conditional execution, that is, if... else. when a certain condition is met, some code is executed; (3) when a certain condition is met, some code is repeatedly executed. Many complex software applications are produced by the magical combination of these three methods. We have already talked about sequential execution and conditional execution. In this exercise, we need to know about loop execution.

In C #, we often use two types of cyclic execution in our daily work. (1) while loop; (2) for loop; of course, C # provides more than two methods for loop execution. If you are interested, check it online. If you still want to know, please contact me.

1. while Loop

While (test condition)

{

When the condition is true, the statements in braces are cyclically executed.

}

When the condition is false, the loop ends and the following statement is executed.

 

 

The execution process of the whille loop is like this.

1. First Judge the test condition of while. If it is true, execute the statement in braces.

2. Execute the statement in braces and then judge the test condition of while. If it is still true, continue to execute the statement in braces.

3. If it is false, end the while loop. Execute the following statement.

 

 

The following is an example to better understand the while loop.

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

Briefly explain this program.

1. Row 17th I ++ is an expression that increases I by 1 each time. For example, I is equal to 1 at the beginning. After the I ++ statement is run, I is changed to 2;

2. This program outputs the current I value in the dos window, and then increases I by 1. If I is not greater than 10, the loop continues.

 

Running result

 

 

Exercise

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

2. If 17th lines of code are injected, what will the result of running the program be?

3. modify the code so that the program can output the I value from 0 to 20 to the dos window.

 

 

 

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

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.