continue word
[1/8] from: maximo::meteorstudios::com at: 17-Oct-2003 11:10
is there any word (I haven't found any) which skips one iteration of a loop at current
point.
like in:
foreach number [ 8 0 2 4 0 5][
if number = 0 [continue]
print 100 / number
]
TIA!
-MAx
---
You can either be part of the problem or part of the solution, but in the end, being
part of the problem is much more fun.
[2/8] from: g:santilli:tiscalinet:it at: 17-Oct-2003 17:31
Hi Maxim,
On Friday, October 17, 2003, 5:10:46 PM, you wrote:
MOA> is there any word (I haven't found any) which skips one
MOA> iteration of a loop at current point.
Not that I know of.
MOA> like in:
MOA> foreach number [ 8 0 2 4 0 5][
MOA> if number = 0 [continue]
MOA> print 100 / number
MOA> ]
You could use THROW and CATCH to implement CONTINUE...
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[3/8] from: rebol:techscribe at: 17-Oct-2003 13:43
Hi Maxim.
The example you bring:
foreach number [ 8 0 2 4 0 5][
if number = 0 [continue]
print 100 / number
]
could just as well (better? ;-) ) be written as
foreach number [ 8 0 2 4 0 5][ [ if number > 0 [ print 100 / number ] ]
I wonder if the combination of if, either and any, all enables us to
cover any and all relevant cases?
Elan
Maxim Olivier-Adlhoch wrote:
[4/8] from: maximo:meteorstudios at: 17-Oct-2003 17:31
> -----Original Message-----
> From: Elan [mailto:[rebol--techscribe--com]]
>
> The example you bring:
[...]
> could just as well (better? ;-) ) be written as
>
> foreach number [ 8 0 2 4 0 5][ [ if number > 0 [ print 100 /
> number ] ]
I was just keeping the example simple ;-)
> I wonder if the combination of if, either and any, all enables us to
> cover any and all relevant cases?
they usually do... but nests get deep and it sometimes gets messy to edit...
its like if the return word did not exist... sometimes its easier just to return a function
when we know the rest is pointless...
you can often just chain tests one after another... in the end, this is slower, but I
rarely am able to notice the difference between .1 and .2 seconds ;-)
I just used a temporary variable instead, like:
;------------------------
success: true
if whatever [
success: false
]
if unless something else [
success: false
]
if success [
do
what
I
need
]
;---------------------------
I tried using any and all and in certain situations but in my problem, it became overly
complex to maintain, so basically, I guess its a case by case decision on the method...
having a continue word would allow me to skip the rest of the code whenever I find something
I know is bad, without having to try and build it up in a fancy mutliple level if/either/any/all
block.
-Maxim
[5/8] from: nitsch-lists:netcologne at: 18-Oct-2003 0:46
Maxim wants
foreach number [ 8 0 2 4 0 5][
if number = 0 [CONTINUE]
print 100 / number
]
which is not available, but
foreach number [ 8 0 2 4 0 5][
catch[
if number = 0 [throw 'continue]
print 100 / number
]
]
does the trick.
use catch/name , throw/name if you need to catch other stuff too.
-Volker
Am Freitag, 17. Oktober 2003 23:31 schrieb Maxim Olivier-Adlhoch:
[6/8] from: antonr:iinet:au at: 18-Oct-2003 15:54
When I want continue I just put loop 1 [...]
inside my loop:
>> repeat n 5 [loop 1 [if n = 3 [break] ?? n]]
n: 1
n: 2
n: 4
n: 5
== 5
Notice the 3 has been skipped.
Anton.
[7/8] from: g:santilli:tiscalinet:it at: 18-Oct-2003 10:00
Hi Elan,
On Friday, October 17, 2003, 10:43:46 PM, you wrote:
E> I wonder if the combination of if, either and any, all enables us to
E> cover any and all relevant cases?
It does, but when you have multiple "exit points", i.e. multiple
places where you want to call CONTINUE, you end up having a lot of
nested IFs. The code is easier to read if you have CONTINUE.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[8/8] from: ingo:2b1 at: 18-Oct-2003 10:07
Hi Anton,
Anton Rolls wrote:
> When I want continue I just put loop 1 [...]
> inside my loop:
of course, you could also use catch and throw this way.
>>repeat n 5 [catch [if n = 3 [throw] ?? n]]
n: 1
n: 2
n: 4
n: 5
== 5
Kind regards,
Ingo