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
While loop
(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!
===Pascal=== {{Further|Pascal (programming language)}} Pascal has two forms of the while loop, '''while''' and '''repeat'''. While repeats one statement (unless enclosed in a begin-end block) as long as the condition is true. The repeat statement repetitively executes a block of one or more statements through an '''until''' statement and continues repeating unless the condition is false. The main difference between the two is the while loop may execute zero times if the condition is initially false, the repeat-until loop always executes at least once. <syntaxhighlight lang="pascal"> program Factorial1; var Fv: integer; procedure fact(counter:integer); var Factorial: integer; begin Factorial := 1; while Counter > 0 do begin Factorial := Factorial * Counter; Counter := Counter - 1 end; WriteLn(Factorial) end; begin Write('Enter a number to return its factorial: '); readln(fv); repeat fact(fv); Write('Enter another number to return its factorial (or 0 to quit): '); until fv=0; end. </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)