Page 1 of 1
While/Wend Prob
Posted: Thu May 02, 2013 7:53 pm
by jerry
I seem to be having a problem using While/Wend,here is an example.
Also see the single step printout that follows the program.
Thanks your help, jerry
Program
Counter = 0 ' Initialize variable.
WHILE Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
WEND ' End While loop when Counter > 19.
PRINT Counter ' Prints 20 in the Immediate window.
Single step
Start program
Ctrl-C detected
5: WEND ' End While loop when Counter > 19.
3: WHILE Counter < 20 ' Test value of Counter.
4: Counter = Counter + 1 ' Increment Counter.
5: WEND ' End While loop when Counter > 19.
3: WHILE Counter < 20 ' Test value of Counter.
4: Counter = Counter + 1 ' Increment Counter.
5: WEND ' End While loop when Counter > 19.
3: WHILE Counter < 20 ' Test value of Counter.
4: Counter = Counter + 1 ' Increment Counter.
5: WEND ' End While loop when Counter > 19.
3: WHILE Counter < 20 ' Test value of Counter.
4: Counter = Counter + 1 ' Increment Counter.
Cold Start
Re: While/Wend Prob
Posted: Fri May 03, 2013 12:58 pm
by basic_mark
Counter = 0 ' Initialize variable.
WHILE Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
WEND ' End While loop when Counter > 19.
PRINT Counter ' Prints 20 in the Immediate window.
Hi Jerry,
Maybe I can help. I am not sure, but it appears you want to see each number from 1 - 20 print to the terminal. If so, you must place your PRINT statement before the WEND statement. Your program as shown below loops and increments the counter to 20 then ends the loop and prints the last value of "Counter."
By now you have probably figured this out on your own.
basic_mark
Re: While/Wend Prob
Posted: Sat May 04, 2013 4:21 pm
by jerry
First, basic_mark thanks for answering.
I see that I did not make the problem clear. The test program as shown, never prints the 20!
The single step print out was to show that when the WEND is executed (line 5) the program jumps
back to WHILE (line 3). The program never goes past the WEND! I am having doubts that the WHILE/WEND
is actually working–
Has anyone actually used the WHILE/WEND statement?
Thanks again,
jerry
Re: While/Wend Prob
Posted: Fri May 10, 2013 10:44 am
by basic_mark
jerry,
I just received my EZSBC1 today and have been playing around with it. I tried your program and it doesn't even load the "WHILE" statement into my module. When I download your program:
Counter = 0 ' Initialize variable.
WHILE Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
WEND ' End While loop when Counter > 19.
PRINT Counter ' Prints 20 in the Immediate window.
All that shows with a list command is:
Counter = 0 ' Initialize variable.
Everything else is gone. I also tried other programing and every time the line with the "While" statement and those after are missing. Probably a bug that Daniel will work out.
It is not a hardship, you can accomplish the same goal with this program:
REM Test FOR jerry
CLRSCR 'clear terminal screen
Counter = 0 'initialize variable
REPEAT
Counter = Counter + 1
UNTIL Counter = 20 'condition
PRINT Counter 'prints variable value to terminal screen
END
basic_mark
Re: While/Wend Prob
Posted: Sun May 19, 2013 2:43 pm
by jerry
basic_mark,
Thanks for your second reply and alternate program.
Sorry it took me a "while" to get back to you.
In a good/bad sort of way, I am glad that I was not crazy and WHILE didn't work for you either.
Bad, Daniel has more work.
I did end up using repeat/until as a replacement on the 3x4 keypad subroutine I was working on.
Thanks again for answering!
jerry
Re: While/Wend Prob
Posted: Tue May 21, 2013 7:19 am
by Daniel
Hi Mark, Jerry
You found a serious bug and it is a little hard to fix. Due to a design choice I made early on the interpreter is restricted to 127 key words. Feature creep has now increased the count to 128 key words and since while is alphabetically last it stopped being a key word. Oops. Even worse, the interpreter fails silently, not a hint of a warning or error. The reason why you see different behaviors is that you have different versions of the interpreter. The WHILE stops being recognized in one version and in the other it is still a key word but no longer works properly. I'm working on fixing it right now and I will send you updated firmware as soon as I fixed it.
Daniel
Re: While/Wend Prob
Posted: Tue May 21, 2013 5:24 pm
by Daniel
I finally managed to find a fix for both issues. It turns out that the incorrect behavior of the WHILE/WEND pair was/is due to a change in the version of the compiler that I use (GCC) and I changed version to resolve another problem related to hardware IO. If I change back to the old version the WHILE/WEND works but the hardware IO is broken. The new compiler produces working code for the IO but WHILE/WEND is broken. Actually, the WEND instruction returns one line before the WHILE when the test condition is false instead of one line after the WEND. Even more annoying, the problem goes away as soon as I load the code using the debugger. I had to do the old fashioned guess and change method of tracking down the problem but I finally found it.
A new issue has now reared its head; I can't add more instructions without rewriting a fairly complicated piece of code. This is going to cause trouble soon.
You will both get new firmware tomorrow.
Daniel
Re: While/Wend Prob
Posted: Tue May 21, 2013 6:01 pm
by basic_mark
Daniel,
If there are limited keyword slots, save them for more useful commands. I feel WHILE/WEND is redundant to start with. To me, REPEAT/UNTIL works just as well.
basic_mark
Re: While/Wend Prob
Posted: Thu May 23, 2013 7:00 pm
by Daniel
basic_mark wrote:Daniel,
If there are limited keyword slots, save them for more useful commands. I feel WHILE/WEND is redundant to start with. To me, REPEAT/UNTIL works just as well.
basic_mark
There are some problems that need a REPEAT/UNTIL loop and others need WHILE/WEND loops. Most of the time one can be rewritten into the other form if the conditional statement is fairly simple. Conditionals of the form ((x>y) AND x >10) OR( Z MOD 5 = 4 ) are not so easy to convert from WHILE to UNTIL.
I need to fix the code to allow for more instructions since I have a pending request to add several instructions.