while and do-while loop structures


while(loop condition){
loop operation
i++;
}
1. Declare and initialize loop variables.
2. Determine whether the loop condition is satisfied, and if so, execute the loop operation; otherwise, exit the loop.
3. After executing the loop operation, judge the loop condition again and decide to continue executing the loop or exit the loop.
*The characteristics of the while loop: judge first, then execute.

do{
loop operation
i++;
}while (loop condition);
1. Declare and initialize loop variables.
2. Perform one cycle operation.
3. Determine the loop condition, if the loop condition is satisfied, the loop will continue to execute, otherwise, exit the loop.
The characteristics of *do-while loop: execute first, then judge.

Chapter Summary
1. The loop structure consists of loop conditions and loop operations. The loop condition is executed repeatedly as long as the loop condition is met.
2. Steps to use loops to solve problems: analyze loop conditions and loop operations, write code using loop syntax, and check whether the loop can exit.
3. When writing the loop structure code, pay attention to the relationship between the change of the loop variable value and the loop condition in the loop operation of the initial value of the loop variable; ensure that the number of loops is correct, and no "dead loop" occurs.
* Infinite loop: A loop that never exits is called an "infinite loop". "Dead loop" is a situation that should be avoided in programming, so for loops, carefully check whether the loop can exit after writing.
4.The characteristic of the while loop structure is to judge first and then execute. The characteristics of the do-while loop structure are executed first, and then judged;

Program debugging (Debug)
1. Program debugging is a general term for tools and methods that satisfy functions such as suspending programs, observing variables, and executing statements one by one. Its main methods include setting breakpoints, single-stepping, and watching variables.
2.F5 single-step into.
3.F6 single step skip.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325223969&siteId=291194637