Trying to read a number at the console

Paul Dufresne dufrp at hotmail.com
Wed Oct 6 15:30:15 PDT 2004


I am trying the following code to read a number at the Console:
===
prototypes addPrototype: #GuessNumber derivedFrom: {Cloneable}
...
gn@(GuessNumber traits) readNumber
"return a number between 1 and 100 read at the Console
if the number is unreadable (=0) then ask again "
[ | num |
  Console reader flush.
  num: ((Console reader next: 3) as: Integer).
  [num isZero]
    whileTrue:
      [
      Console reader flush.
      num: ((Console reader next: 3) as: Integer).
      ].
  Console reader flush.
  num
].
===
But it is not working as expected.
Entering only 2 digits numbers, followed by return, seems to loop forever.
It seems to stop after entering something after having entered a 3 digits 
number.
I expect that if I enter a 2 digit number it simply returns it.
And entering text, should loop as long as a number is not given.

Someone have a clue on what is wrong?

_________________________________________________________________
Gardez le contrôle grâce à la protection contre les fenêtres pop-up 
articulée sur la technologie brevetée Microsoft SmartScreen 
http://join.msn.com/?pgmarket=fr-ca&page=features/popup Commencez dès 
maintenant à profiter de tous les avantages de MSN Premium et obtenez les 
deux premiers mois GRATUITS*.




More information about the Slate mailing list