Re: [Flashforth-devel] For-next and do-loop practise
Brought to you by:
oh2aun
|
From: Mikael N. <mik...@pp...> - 2011-06-25 20:21:05
|
Hi, Some further thoughts: a) B A do ... loop The case a) cannot be translated. It will execute as f). f) B A ?do ... loop : testa #10 #2 - for r@ . next ; ok<$,ram> testa 7 6 5 4 3 2 1 0 ok<$,ram> b) This will also execute as ?do. B A ?do i . loop : testb #10 #2 dup !p>r - for @p . p+ next r>p ; ok<$,ram> testb 2 3 4 5 6 7 8 9 ok<$,ram> /Mike On 16.6.2011 18:56, om1zz wrote: > 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> > > |