Re: [Flashforth-devel] For-next and do-loop practise
Brought to you by:
oh2aun
|
From: om1zz <om...@vo...> - 2011-06-16 15:56:16
|
Mike, thanks! This should definately be put into you FF User Guide!! ?? d) e): K and L are arbitrary values which are added to the loop counter ?? not sure about the limits (the number of times it runs through the loop) a) B A do ... loop B A - 1- for ... next : testa 10 2 - 1- for 0 . next ; ok <#,ram> testa 0 0 0 0 0 0 0 ok <#,ram> b) B A do I ... loop B A dup !p>r - 1- for @p p+ ... next r>p : testb 10 2 dup !p>r - 1- for @p . p+ next r>p ; ok <#,ram> testb 2 3 4 5 6 7 8 ok <#,ram> c) D C do B A do ... I J ... loop loop variable j D C dup !p>r - 1- for B A dup j ! - 1- for @p j @ ... p+ 1 j +! next r>p next variable j : testc 10 2 dup !p>r - 1- for 10 2 dup j ! - 1- for @p j @ . . p+ 1 j +! next r>p next ; ok <#,ram> testc 2 2 3 3 4 4 5 5 6 6 7 7 8 8 ok <#,ram> it shall be probably: ------------------------ variable j : testc 10 2 dup j ! - 1- for 8 3 dup !p>r - 1- for @p j @ . . p+ next r>p 1 j +! next ; testc 2 3 2 4 2 5 2 6 3 3 3 4 3 5 3 6 4 3 4 4 4 5 4 6 5 3 5 4 5 5 5 6 6 3 6 4 6 5 6 6 7 3 7 4 7 5 7 6 8 3 8 4 8 5 8 6 ok <#,ram> d) B A do ... K +loop B A - K / for ... next Issue: Here K is usualy a step of any value (not (B-A/K)) e) D C do B A do ... I J ... K +loop L +loop variable j D C dup !p>r - K / for B A dup j ! L / for @p j @ ... K p++ L j +! next r>p next Issue: Here K and L are usualy steps of any value (not (B-A/K)) f) B A ?do ... loop B A - dup if 1- for ... next then : testf 10 2 - dup if 1- for 0 . next then ; ok <#,ram> testf 0 0 0 0 0 0 0 ok <#,ram> |