version 1.212, 2010/03/07 21:09:38
|
version 1.213, 2010/03/07 21:19:22
|
Line 5349 for @code{ENDIF}, @code{?DUP-IF} and @co
|
Line 5349 for @code{ENDIF}, @code{?DUP-IF} and @co
|
|
|
@cindex @code{CASE} control structure |
@cindex @code{CASE} control structure |
@example |
@example |
@i{n} |
@i{x} |
CASE |
CASE |
@i{n1} OF @i{code1} ENDOF |
@i{x1} OF @i{code1} ENDOF |
@i{n2} OF @i{code2} ENDOF |
@i{x2} OF @i{code2} ENDOF |
@dots{} |
@dots{} |
( n ) @i{default-code} ( n ) |
( x ) @i{default-code} ( x ) |
ENDCASE ( ) |
ENDCASE ( ) |
@end example |
@end example |
|
|
Executes the first @i{codei}, where the @i{ni} is equal to @i{n}. If no |
Executes the first @i{codei}, where the @i{xi} is equal to @i{x}. If no |
@i{ni} matches, the optional @i{default-code} is executed. The optional |
@i{xi} matches, the optional @i{default-code} is executed. The optional |
default case can be added by simply writing the code after the last |
default case can be added by simply writing the code after the last |
@code{ENDOF}. It may use @i{n}, which is on top of the stack, but must |
@code{ENDOF}. It may use @i{x}, which is on top of the stack, but must |
not consume it. The value @i{n} is consumed by this construction |
not consume it. The value @i{x} is consumed by this construction |
(either by an @code{OF} that matches, or by the @code{ENDCASE}, if no OF |
(either by an @code{OF} that matches, or by the @code{ENDCASE}, if no OF |
matches). Example: |
matches). Example: |
|
|
@example |
@example |
: .spell ( n -- ) |
: num-name ( n -- c-addr u ) |
case |
case |
0 of ." zero " endof |
0 of s" zero " endof |
1 of ." one " endof |
1 of s" one " endof |
2 of ." two " endof |
2 of s" two " endof |
dup . |
\ default case: |
|
s" other number" |
|
rot \ get n on top so ENDCASE can drop it |
endcase ; |
endcase ; |
@end example |
@end example |
|
|