IBM SC34-5764-01 Manual do Utilizador Página 121

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 481
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 120
Congratulations! Now you know the best ways to program your REXX execs. Have fun writing programs
that will make your life easier!
/********************************************************/
/* SAMPLE #3: A portion of CATMOUSE EXEC */
/* divided into segments and written with 'more' */
/* indentation and 'more' comments. */
/* Note commands in uppercase (to highlight logic) */
/********************************************************/
/********************************************************/
/* Main program */
/********************************************************/
DO FOREVER
CALL display
/**********************************/
/* Mouse's turn */
/**********************************/
PULL move
IF datatype(move,whole) & move >= 0 & move <=2
THEN SELECT
WHEN mouse+move > len /* mouse hits wall */
THEN nop /* and loses turn */
WHEN cat > mouse,
& mouse+move >= cat, /* mouse hits cat */
THEN mouse = cat /* and loses game */
OTHERWISE mouse = mouse + move /* mouse ... */
END /* moves to new location */
IF mouse = hole THEN LEAVE /* mouse is home safely */
IF mouse = cat THEN LEAVE /* mouse hits cat (ouch) */
/**********************************/
/* Cat's turn */
/**********************************/
jump = RANDOM(1,spring) /* determine cat's move */
IF cat > mouse /* cat must jump left */
THEN DO
IF cat-jump < 1 /* cat hits wall */
THEN nop /* misses turn */
ELSE cat = cat-jump /* cat jumps left */
END
ELSE DO /* cat must jump right */
IF cat+jump > len /* cat hits wall */
THEN nop /* misses turn */
ELSE cat = cat+jump /* cat jumps right */
END
IF cat = mouse THEN LEAVE /* cat catches mouse */
END
/********************************************************/
/* Conclusion */
/********************************************************/
CALL display /* on final display */
IF cat = mouse /* who won? */
THEN say "Cat wins" /* ... the cat */
ELSE say "Mouse wins" /* ... the mouse */
EXIT
Programming Style and Techniques
Chapter 10. Programming Style and Techniques 99
Vista de página 120
1 2 ... 116 117 118 119 120 121 122 123 124 125 126 ... 480 481

Comentários a estes Manuais

Sem comentários