Apart from using streams, part of making code less ugly is splitting it up its separate aaspects. One way it to to do as little as possible within your loop. See how Todd only does one thing within his loop. Apart from looking nicer, doing so improves how you "think" about the problem.
cheers -ben On Tue, 17 Dec 2019 at 23:00, Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote: > Hello, > > My solution to day2 part1 is right this : > > processData: instructions > | opcode index firstNumber secondNumber placeToPut firstNumberIndex > secondNumberIndex | > index := 1. > opcode := instructions at: index. > [ opcode ~= 99 ] > whileTrue: [ firstNumberIndex := instructions at: index + 1. > secondNumberIndex := instructions at: index + 2. > firstNumber := instructions at: firstNumberIndex + 1. > secondNumber := instructions at: secondNumberIndex + 1. > placeToPut := (instructions at: index + 3) + 1. > opcode == 1 > ifTrue: [ instructions at: placeToPut put: firstNumber > + secondNumber ]. > opcode == 2 > ifTrue: [ instructions at: placeToPut put: firstNumber > * secondNumber ]. > index := index + 4. > opcode := instructions at: index ]. > ^ instructions at: 1 > > so its ugly code > > is there a way I can this more the smalltalk way by using streams or > something else. > if so, is there someone who can tell me or can let me see how to make > this cleaner code > > Roelof > > >