Control structures

  • Fully extensible Conditionals
    n even ifTrue: [h: n / 2]
    n even
    	ifTrue: [h: n / 2]
    	False: [h: n pred / 2]
    ans:d= 0 ifTrue: ŠinfinityŠ False: [n / d]
    ../Control structures
    

  • Also fully extensible Loops
    [i < thresh] whileTrue: [i: i * 2]
    [| c |
    c: nextCommand.
    c = 'end' ifTrue: [^self].
    ] loop
    
    [| :exit. c |
    c: nextCommand.
    c = 'end' ifTrue: exit.
    ] loopExit
    

Control structures

Conditionals


    bool ifTrue: blockOrValue
    bool ifFalse: blockOrValue
    bool ifTrue: b1 False: b2
    bool ifFalse: b1 True: b2
Any object that responds to value can be used in place of a block. Value in defaultBehavior returns self.

Looping


    condBlock whileTrue: bodyBlock
    condBlock whileFalse: bodyBlock
    condBlock whileTrue
    condBlock whileFalse

    bodyBlock untilTrue: condBlock
    bodyBlock untilFalse: condBlock

    block loop
    block loopExit
See traits block for more. Feel free to add your own!

[ Previous ] [ Index ] [ Next ]