This shows you the differences between two versions of the page.
cpp:control_structures:break [2012/10/12 02:12] |
cpp:control_structures:break [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== break ====== | ||
+ | syntax | ||
+ | break; | ||
+ | |||
+ | Description: break ends a loop immediately | ||
+ | |||
+ | ===== cpp Sourcecode Example ===== | ||
+ | <code cpp> | ||
+ | #include <iostream> /* including standard library */ | ||
+ | |||
+ | using namespace std; | ||
+ | int main ( void ) { | ||
+ | |||
+ | int i; | ||
+ | i=0; | ||
+ | |||
+ | while (1) { | ||
+ | i++; | ||
+ | if (i==42) { | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | cout << "The answer is " << i <<; | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== output ===== | ||
+ | |||
+ | The answer is 42 | ||