File: while

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (21 lines) | stat: -rw-r--r-- 751 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
S9 LIB  (until <test-expression> <body>)   ==>  unspecific
        (while <test-expression> <body>)   ==>  unspecific

        (load-from-library "while.scm")

The WHILE form first evaluates <test-expression>. When it evaluates
to a true value, it also evaluates <body>, which is a sequence of
expressions. The expressions will be evaluated in order and then the
WHILE form will be re-entered by evaluating <test-expression> once
again. Then WHILE form terminates only if the test expression returns
#F. The value of he form is unspecific.

UNTIL is like WHILE, but evaluates its <body> until <test-expression>
evaluates to truth.

(let ((x 0)
      (y 1))
  (while (< x 10)
    (set! y (* 2 y))
    (set! x (+ 1 x)))
  y)                   ==>  1024