UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software UniBasic Commands Reference - Rocket Software

rocketsoftware.com
from rocketsoftware.com More from this publisher
11.04.2013 Views

Examples The following example is taken from the sample program in Appendix A, “Sample Program,” in Developing UniBasic Applications. This subroutine loops until the user enters a valid order number, or Q (the prompt for order number is already displayed on the screen). 1-430 UniBasic Commands Reference GET_ORDER_NUMBER: * Have the user enter a valid key to a record in the ORDERS file. LOOP DISPLAY @(15,6): INPUT ORDER_NUMBER ORDER_NUMBER = OCONV(ORDER_NUMBER,"MCU") IF NUM(ORDER_NUMBER) OR ORDER_NUMBER[1,1] = "Q" THEN VALID_ORDER_NUMBER = 1 END ELSE VALID_ORDER_NUMBER = 0 MESSAGE = "Order # must be a Number, or the letter 'Q'" CALL DISPLAY_MESSAGE(MESSAGE) END UNTIL VALID_ORDER_NUMBER REPEAT In the next example, the program segment prints and increments POS until it reaches the value of 10: POS=0 LOOP WHILE POS < 10 DO PRINT POS POS +=1 REPEAT In the next example, the program segment prints “Counting” and then increments C. It then evaluates C to see if it is less than eight, and if so, executes the second statement. On the eighth iteration, the program executes the top statement and the loop stops because the condition (C > 8) is met. The program continues execution at the statement following REPEAT. The program does not execute the second statement on the final iteration. C = 0 PRINT "Counting:" LOOP C = C+1 UNTIL C > 8 DO PRINT "C = ":C REPEAT

The result of this program: Counting: C = 1 C = 2 C = 3 C = 4 C = 5 C = 6 C = 7 C = 8 Related Commands UniBasic CASE, CONTINUE, FOR/NEXT LOOP/REPEAT 1-431

The result of this program:<br />

Counting:<br />

C = 1<br />

C = 2<br />

C = 3<br />

C = 4<br />

C = 5<br />

C = 6<br />

C = 7<br />

C = 8<br />

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

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

CASE, CONTINUE, FOR/NEXT<br />

LOOP/REPEAT 1-431

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

Saved successfully!

Ooh no, something went wrong!