For...Until

Monkey Forums/Monkey Programming/For...Until

CopperCircle(Posted 2012) [#1]
Hi, how would I create this C# For statement in Monkey, can't seem to get it to work:

for (Int32 index = firstPoint; index < lastPoint; index++)
{
}

Thanks.


charlie(Posted 2012) [#2]
for local index:int=firstPoint to lastPoint-1

Cheers
Charlie


Samah(Posted 2012) [#3]
If you're looping through a range X to Y, use To:
[monkeycode]For Local index:Int = X to Y[/monkeycode]

If you're looping through a 0-based range, use Until:
[monkeycode]For Local index:Int = 0 Until Length[/monkeycode]


Tibit(Posted 2012) [#4]
In C#

for (Int32 index = firstPoint; index < lastPoint; index++)
{
}

In Monkey (examples):

[monkeycode]
For Local index:int = firstPoint To lastPoint-1 Step 1

Next
[/monkeycode]
[monkeycode]
For Local index:int = firstPoint Until lastPoint Step 1

Next
[/monkeycode]

[monkeycode]
Local index:int = firstPoint
Repeat
index += 1
Until index < lastPoint
[/monkeycode]
[monkeycode]
Local index:int = firstPoint
While index < lastPoint
index += 1
Wend
[/monkeycode]


Samah(Posted 2012) [#5]
That's misleading though. Calling them firstPoint and lastPoint implies a range, which should be using To without the -1. Until is usually used when you're looping over a 0-based collection.


Tibit(Posted 2012) [#6]
I agree that using Until as I did above is far from good coding standard. Myself I only use Until when I loop to the end of a List. The intended purpose here was only to show the syntax.


Gerry Quinn(Posted 2012) [#7]
I had loads of bugs when I started using Monkey from writing To when I meant Until... I think I have finally got used to it now.

Generally Until is what I am using, but To is handy for special cases.


CopperCircle(Posted 2012) [#8]
Thanks, got it working now, im converting a C# Douglas Peucker Points Reduction function to Monkey.