Skip to Content Java Solaris Communities Partners My Sun Sun Store United States Worldwide

»  Spotlight Articles
»  Projects
»  Publications
»  People
»  Awards
»  Events
»  Downloads
»  Internships
»  Contrarian Minds
»  About Sun Labs

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 ]
Would you recommend this Sun site to a friend or colleague?
Contact About Sun News Employment Privacy Terms of Use Trademarks Copyright 1994-2008 Sun Microsystems, Inc.