中断模式中中断和事件的区别
In this tutorial you will learn about difference between break and continue in C.
在本教程中,您将了解C语言中break和continue之间的区别。
The break statement is used in switch or loops and continue statement is used only in loops. When break statement is encountered it immediately stops the switch or loop execution. When continue statement is encountered, all the statements next to it are skipped and the loop control goes to next iteration. Generally we use break and continue with some condition.
break语句用于切换或循环,而continue语句仅用于循环。 当遇到break语句时,它将立即停止切换或循环执行。 遇到continue语句时,将跳过它旁边的所有语句,并且循环控制将转到下一个迭代。 通常,我们使用break并继续某些条件。
Below I have shared difference between break and continue statements along with an example in C.
下面,我分享了break和continue语句之间的区别以及C中的示例。
在C中中断a5knd之间的区别 (Difference Between break a5knd continue in C)
S.No. |
break |
continue |
1. |
break statement is used in switch and loops. |
continue statement is used in loops only. |
2. |
When break is encountered the switch or loop execution is immediately stopped. |
When continue is encountered, the statements after it are skipped and the loop control jump to next iteration. |
3. |
Example: #include<stdio.h> int main(){ int i; for(i=0;i<5;++i){ if(i==3) break; printf(“%d “,i); } return 0; } Output: 0 1 2
|
Example: #include<stdio.h> int main(){ int i; for(i=0;i<5;++i){ if(i==3) continue; printf(“%d “,i); } return 0; } Output: 0 1 2 4
|
序号 |
打破 |
继续 |
1。 |
break语句用于切换和循环。 |
continue语句仅在循环中使用。 |
2。 |
遇到中断时,立即停止执行开关或循环。 |
当遇到continue时,其后的语句将被跳过,循环控制将跳至下一个迭代。 |
3。 |
例: #include <stdio.h> int main(){ 我 for(i = 0; i <5; ++ i){ 如果(i == 3) 打破; printf(“%d”,i); } 返回0; } 输出: 0 1 2 |
例: #include <stdio.h> int main(){ 我 for(i = 0; i <5; ++ i){ 如果(i == 3) 继续; printf(“%d”,i); } 返回0; } 输出: 0 1 2 4 |
If you have any doubts related to above difference between break and continue tutorial then feel free to ask it by commenting below.
如果您对以上中断与继续教程之间的区别有任何疑问,请随时在下面评论以提出疑问。
翻译自: https://www.thecrazyprogrammer.com/2016/01/difference-between-break-and-continue-in-c.html
中断模式中中断和事件的区别