VB.net-Loop

Source: Internet
Author: User

While... End while statement

While (CJ> = 0)

....

End while

Function]:
First, calculate the "expression" after while. If its value is true, execute the loop body, and then calculate the expression after while again, repeat the above process ...... When the value of an expression is calculated, if the value of the expression is false, it will exit the loop and be transferred to the next statement for execution.

Certificate ------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do... Loop statement

1)

Do

Loop while

Loop body at least once

 

2)

Do While <expression>
<Loop body>
Loop

Functions of this statement and while... The functions of the end while statement are completely consistent.

 

3)

 

 

Do... Loop statements first determine the condition and execute the loop body when the condition expression value is false. The statement format and functions are as follows.
[Format]: Do until <expression>
<Loop body>
Loop
[Function]: first, calculate the value of the expression. If the expression value is true, the loop ends. If the expression value is false, the loop body is executed, after the loop body is executed, return to re-test the condition.
[Description]: this loop statement and do while... The only difference between loop statements is that the loop condition of the statement is that the expression value is false.

 

4)

Do... The loop until statement first executes the loop body and then judges the condition. When the value of the conditional expression is false, the loop body is executed. The statement format and functions are as follows.
[Format]: Do
<Loop body>
Loop until <expression>
[Function]: First executes the loop body and then calculates the value of the expression. If the expression value is true, the loop ends. If the expression value is false, the loop body is executed, run the loop body and re-test the conditions ...... It is found that the expression value is true during a test condition, and the loop ends at this time.
[Description]: this loop statement and do... The only difference between a loop while statement is that the loop condition of the statement is that the expression value is false.

-------------------------------------------------- = Bytes ------------------------------------------------------------------------------------------------------

For... Next statement

ForI = 2 ToMath. SQRT (Num) 'indicates whether the I value is a prime number.
If num MoD I = 0 then', if the value of num can be 2 ~ Division of a certain number between the square root of num
Flag = 0' is not a prime number. Set the flag value to 0.
Exit'Exit the For Loop
End if
Next I

 

[Format]: For <cyclic variable >=< initial value> to <End value> [step <step size>]
<Loop body>
Next <cyclic variable>
[Function]: the execution process of this statement is as follows: first, assign "Initial Value" to "cyclic variable", and then compare the value of "cyclic variable" with "final value, if the cyclic variable does not exceed the "final value", execute "loop body", then execute the loop end statement next, and add the value of "loop variable" to the value of "step size, then judge whether the value of "loop variable" exceeds the "End value". If the value does not exceed the "End value", continue to execute the loop body ....... Repeat the above process until the "loop variable" exceeds the "End value" to end the loop, and then execute the next statement of next.

[Description]:
① The cyclic variable, initial value, final value, and step size are all numeric variables. If the step size is 1, it can be omitted.
② The condition for terminating the loop is that the value of the loop variable is "over", not equal to, or greater than or less. The so-called "exceeding" refers to crossing the change direction. If the "step size" is a positive value, "exceeding" means greater than. If the "step size" is a negative value, the value "over" means less. ③ Calculate the number of cycles. The formula is as follows:

 

 

④ The initial value, final value, and step size can be positive, negative, or zero, or an integer or decimal. When the step size is negative, the value of the cyclic variable must be smaller than the final value to terminate the loop.
⑤ If the initial value, final value, and step size are variables, modifying them in the loop body does not affect the number of original cycles. Example: for I = 1 t0 10
Console. writeline (I)
Next I
Console. the writeline (I) statement is executed ten times, and the numbers 1 to 10 are output. When I is equal to 11, I is greater than 10, the loop ends, and the console. the writeline (I) statement will not be executed again. Bytes ---------------------------------------------------------------------------------------------------------------------- Multiple cycles  For cock = 1 to 19'The number of cocks ranges from 1 to 19
For bytes = 1 to 33'The number of hens ranges from 1 to 33
Chicken = 100-cock-yun' the number of chicks is 100 minus the number of brokers and hens.
If (Chicken mod 3 = 0) then' the number of chicks should be divisible by 3
'The cost is exactly 100 yuan, which is a solution.
If (cock * 5 + kernel * 3 + chicken/3 = 100) then
I = I + 1 'scheme No. Plus 1
Textbox1.text = textbox1.text + "Scheme" + CSTR (I) + "Rooster :"_
+ CSTR (cock) + "Hen:" + CSTR (chicken) + "chicken:" + CSTR (chicken) + CHR (13) + CHR (10) 'display the solution information in the text box.
End if
End if
Next iteration
Next cock

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.