Iterations question
[1/6] from: alberto::origen::com::mx at: 16-Aug-2005 21:22
Is there a way to force the next iteration within loops?
I want to know if is posible to code something like
foreach item block-of-items [
if not-good-item [iterate] ;; viod below evaluation
item-evaluation
]
I have made the task easily, defining an extra fuction,
but perhaps I have missed something and is more simple to
force the next iteration.
Thanks!
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
[2/6] from: Izkata:Comcast at: 16-Aug-2005 21:35
Since I don't know of any 'continue yet defined, I usually just do something
like this:
(Using your words)
foreach item block-of-items [
if not not-good-item [
item-evaluation
]
]
Not the best, and looks messy if there's multiple things that would
'continue, but it works.
-Izzy Boy
[3/6] from: alberto:origen:mx at: 16-Aug-2005 22:47
Sure, I also do that when computations inside loops are not too complex...
almost every time
But few times when the evaluation within loops is complex, with a bunch of
nested conditions,
that way of coding make the code looks really ugly.
I hate deep nested code, even when could be short.
compare the two codes, your example is more deeply nested.
mmmhhh. perhaps I still need to shake off from my brain those
line-numbered BASIC vices acquired
when I was a child eh? :-)
10 for l=1 to 500: if peek(l)<>x then next:else poke l,y:next
alberto
On Tue, 16 Aug 2005 21:35:16 -0500, Izkata <[Izkata--Comcast--net]> wrote:
[4/6] from: SunandaDH:aol at: 17-Aug-2005 3:24
Albert:
> Is there a way to force the next iteration within loops?
One way is to wrap a loop 1 around the loop and then use break to exit the
loop 1.
foreach item [1 2 3 4 5 6 7 8 9] [
loop 1 [
print item
if item // 2 = 0 [break]
print [" " item "is odd"]
]
]
Though in many cases refactoring the code may lead to a more elegant
structure.
Sunanda.
[5/6] from: cyphre::seznam::cz at: 17-Aug-2005 10:14
Hi all,
this is another possibility:
items: [1 2 3 4 5 6 7 8 9]
foreach i items [
catch [
print i
if i // 2 = 0 [throw]
print [" " i "is odd"]
]
]
rgeards,
Cyphre
[6/6] from: alberto:origen:mx at: 17-Aug-2005 14:46
Many thanks to Izzy Boy, Sunanda & Cyphre
I think the Cyphre's "catch" approach is what I'm looking for, cool!
Sunanda:
> Though in many cases refactoring the code may lead to a more elegant
> structure.
Absolutely in agreement.
cheers
Alberto
On Wed, 17 Aug 2005 03:14:57 -0500, Cyphre <[cyphre--seznam--cz]> wrote:
> Hi all,
> this is another possibility:
<<quoted lines omitted: 38>>
>> lists at rebol.com with unsubscribe as the subject.
>>
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted