Link to home
Start Free TrialLog in
Avatar of mjacobs2929
mjacobs2929

asked on

SmallTalk Looping

Apologies for posting this to the Java section, but there does not appear to be a SmallTalk area.

The following is supposed to display a series of dialog boxes with the name of each month and index from month1 to month2 inclusive or from month2 to month1 inclusive, depending on which is the larger number. Problem with the code below is that the first loop does not stop at month2, but overruns by one, then steps back. If I run the first loop on its own, it behaves fine. Is there a way to say 'Elseif' in SmallTalk?

Many thanks,
Mab
***************************************

      ifTrue:[
      [month1 <= month2]
            whileTrue:
                  [Dialog warn: (MonthNames at: month1),' ',month1 printString.
                  month1:= month1 + 1].
      [month1 >= month2]
            whileTrue:
                  [Dialog warn: (MonthNames at: month1),' ',month1 printString.
                  month1:= month1 - 1]
      ]
Avatar of Mick Barry
Mick Barry
Flag of Australia image

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mjacobs2929
mjacobs2929

ASKER

Thanks objects!
Something like the above should do the trick. And thanks for the link to the book - Looks Very informative!
no worries, good luck with it :)