Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active January 22, 2021 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nattybear/4e8fa7c516a8a9ea6aa56695d3985c8a to your computer and use it in GitHub Desktop.
Save nattybear/4e8fa7c516a8a9ea6aa56695d3985c8a to your computer and use it in GitHub Desktop.

Selective Controlling

ifTrue:

ifTrue:의 구조는 아래와 같다.

anObject ifTrue: [block-expression-1. block-expression-2]

Boolean 객체에 ifTrue:라는 메세지를 보내고 이때 인자로 블록을 넣는다.

Boolean 객체의 값이 true이면 블록이 실행되고 false이면 블록문이 실행되지 않는다.

| ourVariable |

ourVariable := true.

ourVariable ifTrue: [
  'Our variable is true.' printNl.
]

ifFalse:

ifFalse를 받은 객체가 false이면 블록을 실행한다.

ifTrue:ifFalse:

다른 언어의 if ... else ...와 비슷하다.

an-object
  ifTrue: [
    the-code-block-to-execute
  ] ifFalse: [
    the-code-block-to-execute
  ]
| ourVariable |

ourVariable := false.

ourVariable ifTrue: [
  'Our variable is true.' printNl.
] ifFalse: [
  'Our variable is false.' printNl.
]

Computer Programming with GNU Smalltalk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment