While command

Post Reply
Ellisrh
Posts: 1
Joined: Mon Dec 24, 2012 12:30 am

While command

Post by Ellisrh »

Is there a while command ? I don't see it
If not is there a substitute or work around?

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: While command

Post by Mr. Kibernetik »

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:

Elchoud
Posts: 9
Joined: Wed Nov 21, 2012 3:31 am

Re: While command

Post by Elchoud »

I prefer it to be like this:

A=0
DO:
PRINT A
A=A+1
IF A < 6 THEN DO
..... and the program continues

Dalede
Posts: 131
Joined: Fri Dec 28, 2012 4:00 pm
Location: Grass Valley, CA, USA
Contact:

Re: While command

Post by Dalede »

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

Post Reply