- 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:

推薦閱讀
- Learning Cocos2d-x Game Development
- Istio入門與實(shí)戰(zhàn)
- The Applied AI and Natural Language Processing Workshop
- Manage Partitions with GParted How-to
- 微服務(wù)分布式架構(gòu)基礎(chǔ)與實(shí)戰(zhàn):基于Spring Boot + Spring Cloud
- Hands-On Machine Learning with C#
- OUYA Game Development by Example
- 分布式微服務(wù)架構(gòu):原理與實(shí)戰(zhàn)
- 單片機(jī)開(kāi)發(fā)與典型工程項(xiàng)目實(shí)例詳解
- Source SDK Game Development Essentials
- 超大流量分布式系統(tǒng)架構(gòu)解決方案:人人都是架構(gòu)師2.0
- 微服務(wù)架構(gòu)基礎(chǔ)(Spring Boot+Spring Cloud+Docker)
- 筆記本電腦的結(jié)構(gòu)、原理與維修
- Hands-On One-shot Learning with Python
- The Deep Learning Workshop