First page Back Continue Last page Overview Graphics

Forth Language

Looping:
DO ... LOOP
DO ... +LOOP
?DO ... LOOP
?DO ... +LOOP
I J
BEGIN ... AGAIN
BEGIN ... UNTIL
BEGIN ... WHILE ... REPEAT


Examples:


: 2^ ( n -- 2^n) 1 SWAP LSHIFT ;

: pow2-sum ( n -- m | sum of terms 2^i, i=0,n-1)
    0 SWAP 0 ?DO i 2^ + LOOP ;

10 pow2-sum .