Top: Dspsys Index So, What Have You Learned?

The following questions should test your ability to work with Forth and only correspond to the text which has been presented. When you are finished, press the button marked Grade and your quiz will be graded and returned to you. Good luck!

(1) How many times should the following loop execute?

ok 50 25 5 */ 100 - 100 do get-data write-data loop

(2) Should the loop fail to execute the expected number of times, which of the words we introduced might have caused the loop to exit early?

(3) The following word will work properly except for one mistake. Which line contains the error?

1   : table-of-horrors  ( col row --)   \ Print a table of col*row
2                                       \ numbers for cols and rows
3                                       \ < 10.
4       2dup 10 < swap 10 < and
5       if
6           2dup * 0
7           do
8               i 2 pick mod 0=
9               if  cr
10              then
11
12              i 1+ 10 <
13              if
14                  i 1+ . ."  "
15              else
16                  i 1+ .
17              then
18          loop
19          2drop
20      else    ."col and row must each be less than 10!" cr
21      then  ;

(4) Match the stack notation with the appropriate word.

a) dup

b) 2dup

c) swap

d) rot

e) over

(5) What is the result of each operation below?

a) 7 3 /

b) 81 10 mod

c) 3.33e1 1.11e0 f/

d) 10 2* 2+ 1+

e) 10 3 or

f) 10 3 and

g) 89 not

(6) Answer "true" or "false" for each of the following comparisons.

a) 7 7 <

b) 76 33 >

c) 0 3 0=

d) 3e1 5e1 f<=

(7) For each value of x and y, which code block will be executed?

: if-then-else-fun  ( x y -- )  \ Do stuff based on x and y.
2dup =
if
over 0>
over 0> and
if
[Code Block A]
else
[Code Block B]
then
else
1+ -
if
[Code Block C]
else
[Code Block D]
then
then  ;
a) x=3, y=10    A  B  C  D
b) x=7, y=7     A  B  C  D
c) x=9, y=8     A  B  C  D
d) x=0, y=0     A  B  C  D

Top: Dspsys Index 