<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 25, 2012, at 8:19 AM, <a href="mailto:openbios-request@openbios.org">openbios-request@openbios.org</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><blockquote type="cite">I was wondering if there is a way to implement C's continue <br></blockquote><blockquote type="cite">statement in Forth. I have this loop, and some times I only want to <br></blockquote><blockquote type="cite">execute part of it, and then continue on to the next iteration <br></blockquote><blockquote type="cite">without finishing the current iteration. Is there any way of doing <br></blockquote><blockquote type="cite">this in OpenBIOS?<br></blockquote><br>It certainly can be done. But it sounds like you are making a<br>word with a very big body; this is not the Forth way. Instead,<br>factor your words into smaller words, for example, pull the loop<br>body (the part between WHILE and REPEAT) into a separate word.<br>It then becomes trivial to do your "continue" (and it will also<br>be much more readable!)<br><br><blockquote type="cite">begin<br></blockquote><blockquote type="cite">\ condition<br></blockquote><blockquote type="cite">while<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">\ conditional code<br></blockquote><blockquote type="cite">if<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space: pre; "> </span>CONTINUE<span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>\ skip rest of loop<br></blockquote><blockquote type="cite">then<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">\ rest of loop ...<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">repeat<br></blockquote><br>You don't have anything in here that "increases" the condition<br>(increases some counter, follows a pointer, whatever). Typically<br>you would have that just before the REPEAT, but your example makes<br>it seem you have it between the BEGIN and WHILE. So your code is:<br><br> BEGIN cond WHILE smth IF CONTINUE THEN rest REPEAT<br><br>which you can write as<br><br> BEGIN cond WHILE smth 0= IF rest THEN REPEAT<br><br>(and if you do have an "increment" just before the REPEAT, which<br>you want to run on CONTINUE, you can put it between the THEN and<br>REPEAT in the modified example).<br><br>But, let's build a CONTINUE like you described, just for fun.<br>Let's look at the structure words you used:<br><br>BEGIN ( C: -- dest )<br>WHILE ( C: dest -- orig dest )<br>REPEAT ( C: orig dest -- )<br><br>You want to use your CONTINUE word between WHILE and REPEAT, and<br>it should jump back to "dest"; at compile time, it should not drop<br>the "dest" from the compilation stack. So its stack diagram is<br><br>CONTINUE ( C: orig dest -- orig dest )<br><br>or just<br><br>CONTINUE ( C: dest -- dest )<br><br>For doing an unconditional jump back, there is AGAIN, which is<br><br>AGAIN ( C: dest -- )<br><br>That eats the dest from the compilation stack though, so we want<br>to duplicate it first, using CS-DUP<br><br>CS-DUP ( C: dest -- dest dest )<br><br>Not every system has that; just make it from CS-PICK, like so:<br><br>: CS-DUP 0 CS-PICK ; IMMEDIATE<br><br>And then let's do CONTINUE itself:<br><br>: CONTINUE CS-DUP POSTPONE AGAIN ; IMMEDIATE<br><br>Or you might want a ?CONTINUE which does the equivalent of<br>IF CONTINUE THEN:<br><br>: ?CONTINUE POSTPONE 0= CS-DUP POSTPONE UNTIL ; IMMEDIATE<br><br><br>Hope this helps,<br><br><br>Segher</div></span></blockquote></div><br><div><br></div><div>You are right. My code was a little too long, so refactoring it fixed the problem. I guess I was still programming like a C programmer still. Thanks for the help.</div></body></html>