- C++ Game Development By Example
- Siddharth Shekar
- 128字
- 2021-06-24 14:26:11
Jump statements
As well as condition and iteration statements, you also have break and continue statements.
The break statement is used to break out of an iteration. We can leave a loop and force it to quit if a certain condition is met.
Let's look at the break statement in use:
#include <iostream> #include <conio.h> // Program prints out values to screen int main() { for (int n = 0; n < 10; n++) { if (n == 5) { std::cout << "break" << std::endl; break; } std::cout << "value of n is: " << n << std::endl; } _getch(); return 0; }
The output of this is as follows:

The continue statement will skip the current iteration and continue the execution of the statement until the end of the loop. In the break code, replace the break with continue to see the difference:
#include <iostream> #include <conio.h> // Program prints out values to screen int main() { for (int n = 0; n < 10; n++) { if (n == 5) { std::cout << "continue" << std::endl; continue; } std::cout << "value of n is: " << n << std::endl; } _getch(); return 0; }
Here is the output when break is replaced with continue:

推薦閱讀
- Raspberry Pi 3 Cookbook for Python Programmers
- 數(shù)字邏輯(第3版)
- Mastering Manga Studio 5
- Visual Media Processing Using Matlab Beginner's Guide
- Managing Data and Media in Microsoft Silverlight 4:A mashup of chapters from Packt's bestselling Silverlight books
- Istio實(shí)戰(zhàn)指南
- 微服務(wù)實(shí)戰(zhàn)(Dubbox +Spring Boot+Docker)
- Raspberry Pi Home Automation with Arduino
- Zabbix 4 Network Monitoring
- The Applied Artificial Intelligence Workshop
- 筆記本電腦現(xiàn)場(chǎng)維修實(shí)錄
- 詳解FPGA:人工智能時(shí)代的驅(qū)動(dòng)引擎
- ActionScript Graphing Cookbook
- Learning Microsoft Cognitive Services
- FPGA進(jìn)階開(kāi)發(fā)與實(shí)踐