[#MRDOCS_CHECK_OR_BREAK] = MRDOCS_CHECK_OR_BREAK :mrdocs: Check a value and leave the enclosing loop if it failed. == Synopsis Declared in `<mrdocs/Support/Error/Expected.hpp>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- #define MRDOCS_CHECK_OR_BREAK(var) ---- == Description If the value failed, the macro runs `break`. See `MRDOCS_TRY` for what counts as failed. [,cpp] ---- // Count the leading results that succeeded. std::size_t n = 0; for (Expected const& r : results) { MRDOCS_CHECK_OR_BREAK(r); // stop at the first error ++n; } ---- The loop expands to roughly this (simplified: the real code calls `::mrdocs::detail::failed`): [,cpp] ---- std::size_t n = 0; for (Expected const& r : results) { // MRDOCS_CHECK_OR_BREAK(r); if (failed(r)) { // !r, since r is an Expected break; } ++n; } ---- The value is evaluated once, so a call expression is fine. Things to keep in mind: * Use it only inside a loop or `switch`, and end it with a semicolon. * It's a plain `break`, so inside a `switch` it leaves the `switch`, not the loop around it. * The expansion is two statements. Put braces around it when it's the body of an `if` or `else`. == Parameters [cols="1,4"] |=== | Name| Description | *var* | The value to check. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#