Monday, November 16, 2009

Boolean

The part of the tutorial i covered today focused on Boolean operations. The basic syntax is
(Argument) ifTrue [^'Some Printed Output'] ifFalse [^'Some Printed Output']

Where the argument is something along the lines of 1 < 10 and the ^ (shown as an up arrow in Squeak) is the command to return a value. This is one of the code blocks i evaluated which was included in the tutorial:

| dir pos |
pos := 'Chalk Farm'.
dir := ''.
[dir isNil or: [dir isEmpty]] whileTrue: "loop Prompter until a char has been entered"
[ dir := FillInTheBlank request: 'Enter a one-letter direction: N,S,W,E' ].
( dir = 'N' )
ifTrue: [ pos := (Map at: pos) n.
Transcript show: 'Moved to ', (Map at: pos) description ]
ifFalse: [ Transcript show: 'This has not been implemented yet!'].

Ignoring some the the classes created earlier in the tutorial the code is basically creating two temporary variables (dir and pos), setting pos equal to the string 'Chalk Farm,' setting dir equal to nil and comparing a user input to deturmine the aspects of locations around the variables.

No comments:

Post a Comment