Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reduce (computer algebra system)
(section)
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.
Anti-spam check. Do
not
fill this in!
==== Repetition statements: while ... do; repeat ... until ==== The two loop statements <div class="center" style="width: auto; margin-left: auto; margin-right: auto;"> <code>while</code> ''boolean expression'' <code>do</code> ''statement''<br /><code>repeat</code> ''statement'' <code>until</code> ''boolean expression'' </div> are closely related to the conditional statement and execute ''statement'' repeatedly a number of times that need not be known in advance. Their difference is that <code>while</code> repetition stops when ''boolean expression'' becomes false whereas <code>repeat</code> repetition stops when ''boolean expression'' becomes true. Also, <code>repeat</code> always executes ''statement'' at least once and it can be used to initialize ''boolean expression'', whereas when using <code>while</code> ''boolean expression'' must be initialized before entering the loop. The following <code>while</code> statement computes the value of <math>n!</math> as the value of the variable <code>fac</code>. Note that this code treats the assignment <code>n := n - 1</code> as an expression and uses its value. <syntaxhighlight lang="octave" copy> n := 5; fac := n$ while n > 1 do fac := fac*(n := n - 1); fac; </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)