Is there a while command ? I don't see it
If not is there a substitute or work around?
While command
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: While command
You are right, there is no WHILE command.
How to substitute. For example, this "WHILE" code
A=0
DO WHILE A <= 5
PRINT A
A=A+1
LOOP
can be substituted with
A=0
DO: IF A > 5 THEN END
PRINT A
A=A+1
GOTO DO
END:
How to substitute. For example, this "WHILE" code
A=0
DO WHILE A <= 5
PRINT A
A=A+1
LOOP
can be substituted with
A=0
DO: IF A > 5 THEN END
PRINT A
A=A+1
GOTO DO
END:
Re: While command
I prefer it to be like this:
A=0
DO:
PRINT A
A=A+1
IF A < 6 THEN DO
..... and the program continues
A=0
DO:
PRINT A
A=A+1
IF A < 6 THEN DO
..... and the program continues
Re: While command
There is a difference in the two solutions. The one by Elchoud will always execute the statement at least once since the test is at the end. This is similar to the for/next loop. It tests on the next command so it will always execute once. The earlier solution by Mr. Kibermetic tests at the beginning and will exit before doing anything. So it really depends on what you need.
Dale
Dale