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!
===Racket=== {{Further|Racket (programming language)|Scheme (programming language)}} In Racket, as in other [[Scheme (programming language)|Scheme]] implementations, a ''named-let'' is a popular way to implement loops: <syntaxhighlight lang="racket"> #lang racket (define counter 5) (define factorial 1) (let loop () (when (> counter 0) (set! factorial (* factorial counter)) (set! counter (sub1 counter)) (loop))) (displayln factorial) </syntaxhighlight> Using a macro system, implementing a ''while'' loop is a trivial exercise (commonly used to introduce macros): <syntaxhighlight lang="racket"> #lang racket (define-syntax-rule (while test body ...) ; implements a while loop (let loop () (when test body ... (loop)))) (define counter 5) (define factorial 1) (while (> counter 0) (set! factorial (* factorial counter)) (set! counter (sub1 counter))) (displayln factorial) </syntaxhighlight> However, an imperative programming style is often discouraged in Scheme and Racket.
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)