Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!
Editing break
From Quake Wiki
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | Syntax:<br/> | |
+ | <code>break;</code> | ||
− | + | This statement is used for flow control. It is meant to be placed inside a loop (either do or while) and will cause execution to exit out of the loop and continue on. | |
− | |||
− | + | Ex: | |
− | + | <pre>while(TRUE) | |
− | + | { | |
− | + | x = x + 1; | |
− | + | if (x > 5) | |
− | + | break; | |
− | + | } | |
− | + | </pre> | |
− | + | ||
− | + | In this example, the condition in the while() loop will always evaluate to true, so this loop would normally never end. By placing a counter inside the loop and checking it's value, we manually break out of the loop by executing the break; statement when x is larger than 5. | |
− | + | ||
+ | In general, it is discouraged from overusing break as a properly written do or while loop should have it's own conditions for exiting and overuse of break, especially in large loops, can impact readability. This does not mean you should never use it, only to be sure it is actually needed. | ||
[[Category:QuakeC Function]] | [[Category:QuakeC Function]] |