Computer small white self-taught software programming-. NET syntax basics of looping statements, pure tips dry

Source: Internet
Author: User
Tags logical operators

Write code also to read, love the whole stack, more love life. Daily update of original it programming techniques and daily practical videos.

Our goal is: To play with the server Web development, to understand the mobile side, the computer client is a cinch.

This tutorial is a basic tutorial for anyone who is interested in learning software development. Of course, because of the coherence of technology, it is recommended to view in order.

Last class: Computer small white learning software development-c# Choice statement, exception capture, offensive programmer

Course list: Because the headlines can not be customized catalogue, we are concerned about: "Do the full stack siege Lion" public number. Reply to ". NET directory" and get it. The public number also contains a lot of learning tutorials, waiting for you to come ~

This series of tutorials is about C # syntax. For specific development tools and basics, it is recommended to view previous tutorials.

The last time you were explaining an IF condition statement. Review the big question:

  1. The SELECT statement is based on the criteria, select the specific part of the code that should be executed.

  2. The condition is not set up in fact there is a data type. He is a bool. BOOL consists of only two values, True (True) and False (false). For example, you can assign values like this:

  3. The value that is compared by the logical operator is the bool type.

  4. Common logical operators:

Give me a question for you to do:

    1. Please compile the program to determine whether the input positive integer is both 5 and the integer multiples of 7. If so, the output is yes;

    2. Input Fahrenheit Celsius, convert it to the temperature of the layer Celsius and output (conversion formula c= (5*F)/9+32)

    3. Enter two numbers to output their maximum value.

    4. To find the trapezoid area. The upper and lower floor heights are 3,4,4 respectively.

    5. Enter three integers x, y, Z, please put these three numbers from small to large output.

The specific code is concerned with the public number and will be explained in the next course.

First, the circulation

Go to the content of this lecture: cycle.

Loops, so the name Incredibles is the syntax for looping through a piece of code. We can use this code to achieve the effect of bulk code execution.

1. While loop

Is the calculation of the number of 1-100 integers.

  1. While can be understood as the meaning of "when". You can see that the whie is followed by parentheses. That's right. The contents of this parenthesis also indicate the condition. The conditional usage explained in the if is still available here.

  2. If the condition is true, the contents of 2 are executed. After the execution of 2, then to determine whether 1 conditions are established. Establishment continues to execute 2. Otherwise, 3.

is also based on the criteria to determine whether to execute the code.

For example, we can output 10 "Do full stack siege Lion" string. :

Effect:

I in this, is purely to control the number of cycles.

Then 1-100 and the program can understand this:

In: i = i+1 sum = sum + i in the form of code can be abbreviated to

I+=1, sum+=i, are also valid for other operators such as:

i = i*5:i*=5 i = i-5: i-=5

For the special form of i+=1, it can be shortened to i++

2. Do.....while Cycle

Calculate between 1-100 and the following:

Do and loop flow:

  1. The content of 1 is executed by default. After execution, determine whether condition 2 is established.

  2. 1 of the content will continue to be established

  3. If it is not established, it shall proceed as permitted.

In fact, the difference from while is that the do-while loop executes the code once regardless of whether the condition is established. The while condition is not enforced.

3. For loop

Calculate between 1-100 and the following:

For loop execution Process:

  1. First do 1

  2. Then determine whether the condition 2 is established.

  3. If the contents of the execution loop are set up. Which means 3.

    1. 3 Execution is complete 4

    2. 4 execution completed, determine whether the condition 2 is established

    3. Set up then execute 3, otherwise jump out of the loop and do the following 5

  4. If it does not, jump out of the loop to execute the following content.

Here are a few more contact programs, and it's recommended to consider:

After-school practice topics:

    1. Calculates the sum of odd sum and even numbers between 1-100

    2. Calculate 1+1/2+......+1/100

    3. Enter a three-digit number to output their single-digit, 10-digit, and hundred-digit numbers.

    4. Seeking 1*2*3*..........*n. Cycle

    5. 1+2+3+4+6+7+8+9+11++.+99= (multiples of 5)

    6. In order to satisfy the largest n in the 1+2+3+...+n<500, and to find and write program implementation.

This article by doing full stack Siege Lion original debut, if reproduced please declare the source.

WX platform: Make full stack siege Lion, submit Wx:aiquanzhan

Computer small white self-taught software programming-. NET syntax basics of looping statements, pure tips dry

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.