-
In the end, there are only two cycle conditions, 0 and 1
while(**.)
*If it is true, it is 1, and if it is not true, it is 0
Set up on the execution of {} inside the content. If it doesn't hold, it exits the loop.
It is also possible to make the while condition always valid (e.g., while(1)), and use a judgment condition in the loop body, and break out of the loop if the condition is true.
-
Let's use the for statement, this one is easier to use.
for(initial variable; cyclic conditions; Cyclic variables).
i<10;i++)
-
Would you for statements not?
const size=100
for(i=0;i!=size;++i)
Equivalent. i=0
while(i!=size)+i;
-
Syntax format: while (loop condition).
Execution statements (blocks);
"Loop condition" means that when the set condition is satisfied, the statement in {} below while is executed;
"Execution Statement" refers to the statement that the program will execute when the condition meets the "loop condition".
As. int i = 0;
while(i < 9)
i++;The "loop condition" here is that when the variable i is less than 9, the statement in {} is executed.
The execution statement is "i++".
About do while
Syntax format: do
Execution statements (blocks);
while (loop condition).
Where the execution statement and loop condition are the same as while. The difference between the two is that a do while will be executed once and then judged regardless of whether the loop condition is true in the first place. In other words, while first determines whether the loop condition is true, and then executes the internal execution statement (block). do while executes the internal execution statement (block) first, and then determines whether the loop condition is true, and if it is true, it returns to the "execution statement (block)".
LZ still has something I don't understand, just come to it. Yes
-
There are three types of common cyclic statements: for statements, while statements, and do while statements.
for:for is a loop statement, which well embodies the three problems that should be paid attention to in correctly expressing the loop structure
Initialization of control variables.
The condition of the cycle.
The cycle controls the update of the elimination variables.
for expression:
Expression 1: It is generally an assignment expression that assigns an initial value to the control variable.
Expression 2: A relational expression or a logical expression that controls conditions in a loop.
Expression 3: Generally an assignment expression, which increases or decreases the amount of the control variable.
Statements: Loops, compound statements must be used when there are multiple statements.
while:
The while structure loop is a when type loop, which is generally used when the number of loops is not known. What maintains the loop is a conditional expression, the condition is true to execute the loop body, and the condition is not true to exit the loop.
The while statement is in the form of:
Circular statements. Circulating bodies.
Conditional expressions are judged before each loop is executed.
Here the expression is the condition for whether the loop can continue, and the statement is the loop body. As long as the expression is true, the loop body statement is executed. Otherwise, the cycle will be stopped, and the circular sentence will be executed.
do while:
do…The while statement is structured as an until type loop, and is also used when you don't know the number of loops. do…The difference between while and while is do....The while structure is the condition for judging the loop after executing it.
-
A loop statement is a statement used to repeatedly execute a statement (loop body), which contains a control expression, and the control expression must be judged every time the loop is executed, and if the expression is true, the loop will be continued.
In many practical problems, there are many regular repetitive operations, so it is necessary to repeat certain statements in the program. A set of statements that are repeated is called a loop, and whether or not it can continue to repeat determines the end of the loop and relaxes the conditions. The cyclic structure is a process structure in which a certain section of a program is repeatedly executed under certain conditions, and the program that is repeatedly executed is called a cyclic body.
A loop statement consists of two parts: the loop body and the end condition of the loop. The simplest loop statement is naturally the VB statement (i.e., Visual Basic).
The while keyword is used to check do....loop statement. There are two ways to check the condition:
Check the condition before entering the loop (like the chkfirstwhile example below); Or check the striped antecedent after the loop has run at least once (as in the chklastwhile example below).
During chkfirstwhile, if the initial value of mynum is set to 9 instead of 20, the statement in the loop body will never be executed. During chklastwhile, the brightness statement in the loop body is executed only once, because the condition is already false when checked.
-
Differences: 1. Different usage scenarios:
For is generally used when the number of executions is known, and while is generally used for conditional loops.
2. The difference between the two cycles in the construction of an endless loop:
The conditions in the while loop are regarded as expressions, so when using while to construct an endless loop, the true in it is actually regarded as an expression that is always true, which is easy to cause confusion, and some tools such as pc-lint will think that something is wrong, so when constructing an endless loop, it is best to use for(;; to proceed.
3. The difference between the two cycles and ordinary cycles:
When looping an array, in general, it is more convenient to use a for loop if the loop variable is increased after each loop has been processed.
If you want to increase the loop variable during loop processing, it is more convenient to use a while loop.
Also, when using the for loop statement, if the loop condition in it is very long, you can consider using a while loop instead to make the typography format of ** look better.
Usage: For loops can be set to the number of times, and there is no limit to the number of times the while loop condition is met.
Therefore, the heavens will descend on the people, and they must first suffer their minds, strain their muscles and bones, starve their bodies and skins, empty their bodies, and act chaotically, so they are motivated to endure and gain what they cannot.
Don't mess with the oath, because it will come true. God doesn't carry it out, I do! "Domineering!
Another way to look: select ,select zy ,sum(zy as yjjefrom zy tbkk,zy brry >>>More
I have all of them, some of them are easy to use, and some of them are still trying them out. Use this one I sent directly.,Don't experiment by yourself.,It's really complicated and you need to save it directly. >>>More
"cookie" means "little cookie" in Chinese.
These scary "cookies" are hidden in our computers, faithfully recording all our actions online. It is still in Chinese windows >>>More