Some auxiliary functions are sometimes used in loop statements, including break and continue. The break statement exits the loop and no longer executes the remaining statements of the loop. The continue statement ends the current loop and returns to the beginning of the loop to start a new cycle.
The function of the break statement is to stop the currently executing loop (for, while, do while) or switch multi-branch program structure, and do the following of these structural functions Content. In the switch statement, break is used to cause the process to jump out of the switch statement and continue executing the statement after the switch.
In loop statements, break is used to jump out of the nearest closed loop body.
For example, after executing break, the following code continues to execute the statement at "a=x 2;" instead of jumping out of all loops:
for (x=0;x<5;x++ ){ for (i=0;i<5;i++ ){if (i==1)break;} a=x+2; //break跳至此处 ...}
continue statement The function is to end the currently executing loop (for, while, do...while), and then execute the next loop. That is, the statements in the loop body that have not yet been executed are skipped, and then a judgment is made whether to execute the loop next time.
In the for loop, continue is used to execute the next loop.
In while loops and do...while loops, continue is used to execute the judgment of conditional expressions.
For example: Output an odd number between 1 and 100.
for (int i=0; i<=100; i++){ if (i%2==0) continue; //当i被7整除时,执行continue语句,结束本次循环,即跳过cout语句,转去判断i<=100是否成立。只有i不能被7整除时,才执行cout函数,输出i。 cout << i << endl; }
To sum up, the difference between the continue statement and the break statement is that the continue statement only ends the current loop, rather than terminating the execution of the entire loop. The break statement ends this loop and no longer performs conditional judgment.
[Recommended course: C Video Tutorial]
The above are the details of break and continue in the C loop statement. For more information, please pay attention to other related articles on the PHP Chinese website!
The above is the detailed content of The impact of break and continue in C++ loops on functions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment