Skip to content
Snippets Groups Projects
Commit e7863e89 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add do...while documentation

parent 30c256fc
No related branches found
No related tags found
1 merge request!145git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
......@@ -1880,7 +1880,7 @@ We give a final illustration
*** ~for~ loops
~pugs~ allow to write ~for~ loops. It follows the ~C++~ syntax
~pugs~ allows to write ~for~ loops. It follows the ~C++~ syntax
#+BEGIN_SRC pugs :exports code
for (declarationinstruction ; condition ; postinstruction) statement
#+END_SRC
......@@ -1937,8 +1937,43 @@ To fix the previous code, one can write
One gets
#+results: for-no-decl
*** ~do...while~ loops
*** TODO do while loops
The second kind of loops that can be written is the ~do...while~
construction which executes /at least/ one time the enclosed ~statement~.
#+BEGIN_SRC pugs :exports code
do statement while (condition);
#+END_SRC
The ~statement~ is either a single instruction or a block of
instructions. The ~condition~ is an expression of boolean value (type
~B~).
#+NAME: do-while-instr
#+BEGIN_SRC pugs :exports both :results output
let sum:N, sum = 0;
let i:N, i = 0;
do
sum += i++;
while (i<=10);
cout << "sum = " << sum << "\n";
#+END_SRC
This code produces
#+results: do-while-instr
However, to ease the reading, it is probably better to write
#+NAME: do-while-block
#+BEGIN_SRC pugs :exports both :results output
let sum:N, sum = 0;
let i:N, i = 0;
do {
sum += i;
++i;
} while (i<=10);
cout << "sum = " << sum << "\n";
#+END_SRC
It gives also
#+results: do-while-block
*** TODO while loops
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment