i++

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

i++

Chris Cunnington

I have a piece of code in an OpenGL book:

for(angle = 0.0f; angle <= GL_PI; angle += (GL_PI/20.0f))
     { //the expression}

It looks to me like something I see in JavaScript a lot:

i=0; i<10; i++

But it seems to be blind spot in my Smalltalk knowledge. I keep trying:

x := 0.
(x < 10) whileTrue: [Transcript show: x.  x := x + 1]

or

(1 to: 10) do: [: x | Transcript show: x.]

I don't see how to iterate the variable and then print it. It's as
thought a value changed in a block wouldn't get fed back into that block.

Any help would be appreciated.

Chris
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: i++

Michael Haupt-3
Chris,

On Tue, Mar 16, 2010 at 3:12 PM, Chris Cunnington
<[hidden email]> wrote:
> But it seems to be blind spot in my Smalltalk knowledge. I keep trying:
>
> x := 0.
> (x < 10) whileTrue: [Transcript show: x.  x := x + 1]

with [x<10] instead of (x<10), this works perfectly for me, printing 0123456789.

> (1 to: 10) do: [: x | Transcript show: x.]

And this works out of the box.

(Squeak, trunk.)

> I don't see how to iterate the variable and then print it. It's as thought a
> value changed in a block wouldn't get fed back into that block.

I'm afraid I don't see the problem.

Best,

Michael
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: i++

Chris Cunnington
In reply to this post by Chris Cunnington
Thanks, that's got it.
I couldn't see it for some reason.
Cheers,
Chris
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: i++

Tobias Pape
In reply to this post by Michael Haupt-3
Hello —,

Am 2010-03-16 um 15:34 schrieb Michael Haupt:

>> (1 to: 10) do: [: x | Transcript show: x.]
>
> And this works out of the box.

Moreover, often this is even better to read:

1 to: 10 do: [:x | Transcript show: x].

So Long,
        -Tobias

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners