[REBOL] Re: fun with for loops
From: carl:cybercraft at: 2-Aug-2002 18:22
On 02-Aug-02, Charles wrote:
> Howdy folks. Got a bit of a difficulty here. Say I'm evaluating a
> for loop, like reading lines of text from a file. At the beginning
> of my for loop, I have it check to see if the line is commented,
> blank, or neither. If it's commented or blank, I want it to just
> skip to the next iteration of the for loop; however, if it's
> neither, let it keep going. I would prefer to do this with a simple
> if [] as opposed to a heavy either [][]... 'break' doesn't do what I
> need - it kills the for loop entirely, instead of skipping to the
> next iteration. If I use either [][], I have to do: either
> condition? [
> if true do this
> ][
> if false
> do these
> next 20 lines
> all indented
> with more indentation
> yet to come
> very long lines
> ]
> You follow me? It's a coding habit I've picked up from another
> language. Thanks folks.
I'm not sure I do follow you, but if you just want to use an if
instead of an either, just use 'not to switch the result of your
condition around. ie...
parse-line: func [file][
foreach line file [
if not any [line = "" line/1 = #";"][print line]
]
]
>> a-file: ["aaa" "" "bbb" "; a comment" "ccc"]
== ["aaa" "" "bbb" "; a comment" "ccc"]
>> parse-line a-file
aaa
bbb
ccc
HTH.
--
Carl Read