diff --git a/doc/userdoc.org b/doc/userdoc.org index 4d8c90f29e5c996b8ab9591bca45cf88cf06a30c..3f8ae8f9c04cba5b031d033b2c00e6be4e2b4b0d 100644 --- a/doc/userdoc.org +++ b/doc/userdoc.org @@ -2005,6 +2005,48 @@ The result is #+results: while-block +*** ~break~ and ~continue~ keywords. + +These *keywords* are used to control loops behavior from enclosed loop +statements. They follow their ~C++~ counterparts. + +- The ~continue~ keyword is used to skip the instructions that follow in + the loop statement and continue the loop. + +- The ~break~ keyword is leaves the current loop. + +An example of use of the ~continue~ keyword is +#+NAME: nested-continue +#+BEGIN_SRC pugs :exports both :results output + for (let i:N, i = 0; i < 5; ++i) { + cout << i << ": "; + for (let j:N, j=0; j < 5; ++j) { + if (j<i) continue; + cout << j << " "; + } + cout << "\n"; + } +#+END_SRC +The result is +#+results: nested-continue + +Replacing the ~continue~ keyword by a ~break~ +#+NAME: nested-break +#+BEGIN_SRC pugs :exports both :results output + for (let i:N, i = 0; i < 5; ++i) { + cout << i << ": "; + for (let j:N, j=0; j < 5; ++j) { + if (j>i) break; + cout << j << " "; + } + cout << "\n"; + } +#+END_SRC +changes the output to +#+results: nested-break + +Obviously the behavior is the same using ~do...while~ or ~while~ loops. + ** TODO Functions<<functions>> *** Pure functions