For...Until
Monkey Forums/Monkey Programming/For...Until
| ||
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. |
| ||
for local index:int=firstPoint to lastPoint-1 Cheers Charlie |
| ||
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] |
| ||
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] |
| ||
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. |
| ||
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. |
| ||
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. |
| ||
Thanks, got it working now, im converting a C# Douglas Peucker Points Reduction function to Monkey. |