Do/enddo – Remote Processing CAMBASIC User Manual

Page 71

Advertising
background image

Comm ands - 38

DO/ENDDO

Statements

SYNTAX:

DO value
.
.
.
ENDDO

PURPOSE:

To execute a loop a number of times quickly.

REMARK S:

value range is 1 to 65535. It can be a number or variable.

The DO /EN DDO statements cause a list of statements to be exec uted for a num ber of times. It is 3
times faster than using a FOR/N EXT loop.

Y o u c a n N O T e xi t a D O / E N D D O wi th th e E XI T st a te m e nt A w ay to g r ac e fu ll y e x it a D O / E N D D O
loop is to set DO = 1 then GOTO the line at ENDDO.

NOTE: Nesting of DO /EN DDO loops is NOT permitted. This construct' s speed is due to the use
of a single counter.

EXAMPLE:

10 A= - 45
20 DO 45
30 INC A:PRINT A
50 ENDDO

Nesting DO/ENDDO loops is NOT allowed. An example of what NOT to do is shown below.

DO 25

GOSUB ..routine

ENDDO
'
..routine
DO 50

A = AIN(0) + A

ENDDO
RETURN

A DO loop counter empty error is returned after the GOSUB routine.

ERROR:

< ENDDO> – if ENDDO encountered without corresponding DO.
< DO loop counter em pty> - When a DO loop is nested and the most recent one was completed.

Advertising