11.04.2013 Views

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In the following example, the program segment prints the string 10,8,6,4,2,. The loop<br />

terminates before printing 0 because the FOR/NEXT statement specifies that when<br />

the variable I falls below 1, the loop terminates.<br />

FOR I = 10 TO 1 STEP -2<br />

PRINT I:",":<br />

NEXT I<br />

In the next example, the optional WHILE expression clause creates a secondary<br />

condition for the termination of the FOR/NEXT structure. While a normal<br />

FOR/NEXT loop repeats the contained statements 10 times, the WHILE clause<br />

results in this example stopping after only three repetitions. This occurs because the<br />

value read from the DATA statement by the INPUT command exceeds the value of I<br />

on the third iteration. The WHILE clause with the same statements results in the loop<br />

terminating after one iteration. After the iteration, I is less than K, satisfying the<br />

condition and causing the loop to stop.<br />

K=50<br />

DATA 3,4,2,51,8,10,15,3,2,8<br />

FOR I = 1 TO 10 WHILE I < K<br />

INPUT K<br />

PRINT I,K<br />

NEXT I<br />

Related <strong>Commands</strong><br />

<strong>UniBasic</strong><br />

CASE, LOOP/REPEAT<br />

FOR/NEXT 1-277

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!