Eric-

Here is the for loop I was having trouble with (I had to recreate it 
from memory.)

article: make block! 50
article: load %news.txt
article_length: length? article

news_page: make string! 1000

paragraph_begin: make tag! <P>
paragraph_end: make tag! </P>

for add_tags 3 article_length 1 [
    paragraph_with_tags: join paragraph_begin [ article add_tags ] 
paragraph_end
    append news_page paragraph_with_tags
]



> 
>Hi Ryan,
> 
>Could you show me some code where you've had trouble? I'm not aware of 
any
>documentation other than the User's Guide and what you get by using 
HELP.
>I've found that most of my problems with the loop functions are solved 
by
>realizing that they are just functions that take arguments, and that 
you have
>to pay close attention to how the arguments you feed them are going to 
look.
> 
>>> ? while
>While a condition block is TRUE, evaluates another block.
>Arguments:
>    cond-block --  (block)
>    body-block --  (block)
> 
>WHILE takes two block arguments. The first one is repeatedly 
evaluated, and
>as long as that evaluation returns a true value, the second one is 
also
>evaluated.
> 
>>> ? for
>Repeats a block over a range of values.
>Arguments:
>    word -- Variable to hold current value (word)
>    start -- Starting value (number series money time date char)
>    end -- Ending value (number series money time date char)
>    bump -- Amount to skip each time (number money time char)
>    body -- Block to evaluate (block)
> 
>FOR takes five arguments! I'm always getting the number wrong, and the 
error
>messages are always confusing. Basically what you want is a word, 
three
>numbers, then the block to be evaluated.
> 
>And so on ... Now why would your FOR statement ignore part of your 
block?
>Perhaps there's an if statement that's not right. Perhaps you have a 
block
>within your FOR block that you expect to be evaluated, but it's just 
sitting
>there because it's not the argument of an IF or a LOOP or a TRY or a 
DO or a
>... Perhaps you're trying to use a word argument of FOR or FOREACH 
after
>you've exited from the FOR or FOREACH block.
> 
>>> for x 0 4 1 [print x]
>0
>1
>2
>3
>4
>>> print x
>** Script Error: x has no value.
>** Where: print x
> 
>X here is strictly local to the FOR block. It looses its value once 
you leave
>that block. In such a case you should do:
> 
>>> x: 0 while [x <= 4][print x  x: x + 1]
>0
>1
>2
>3
>4
>== false
>>> print x
>5
> 
>Finally, since REBOL code uses no delimiters for their own sake, if 
get the
>number of arguments to one function wrong, the error may show up some 
place
>where you'd never expect. You've got to keep looking at the help for 
the
>functions you use, and keep your code formatted to make it as 
transparent as
>possible how everything should evaluate out.
> 
>Good luck!
>Eric
>
>

Reply via email to