In C, the keyword while is used to proceedCycle operation, and the so-called cycle isRepeat one or more commands。In fact, to understand what kind of state the loop structure in the program structure is, you only need to contact yourself to listen to the state of the loop ***.
In the specific C language, there are two forms of loop structure that use the while keyword, namelywhile and do....whileThe verbal description may not be clear enough, but the difference between the two forms is very straightforward through the demonstration.
As you can see from the figure above, the two forms of while loops are mainly different in the location of the while keyword.
In addition, the form of use of while in concrete **, like calling a function method, has parentheses, and the parentheses are insideDeclare the condition for exiting the loop operation
Like the for loop, the while loop must have a clear exit condition, otherwise the program will fall into an endless loop, which tends to drain the computer's resources from software to hardware, especially when the loop operation is complex.
In addition to declaring the exit condition of the loop operation in parentheses after the while, there is also a special exit form that declares the while exit condition as true and combines the if condition statement and the break keyword in the loop body, as shown below.
Either form of while loop can be implementedElement traversal functionwithWait for a specific action
The above is the basic usage of while loops in the C language, and more advanced uses need to be experienced and experienced in actual programming.