Liberty BASIC Help Online

DO LOOP
  do
      'code in here
  loop while booleanExpr
 
'execute the code inside this loop at least once
do
    'code in here
loop until booleanExpr
 
do while expr
    'some code
loop
 
do until expr
    'some code
loop
 
Description:
DO and LOOP cause code to be executed while a certain condition evaluates to true, or until a certain condition evaluates to true. The "while" and "until" parts of this expression can be located either in the "DO" statement or the "LOOP" statement. The following form is good for cases when you want a loop that always executes once and then only loops back as long as a condition is met. It will continue looping back and executing the code as long as the booleanExpr evaluates to true.
 
    'execute the code inside this loop at least once
    do
        'code in here
    loop while booleanExpr
 
You can also use the UNTIL keyword to reverse the logic of the expression:
 
    'execute the code inside this loop at least once
    do
        'code in here
    loop until booleanExpr
 
Usage:
'examples using "loop while" and "loop until"
    print "print a zero"
    do
        print a
        a = a + 1
    loop while a > 10
    print
 
    print "print 1 to 9"
    do
        print a
        a = a + 1
    loop while a < 10
    print
 
    'examples using loop until
    print "print a zero"
    do
        print b
        b = b + 1
    loop until b = 1
    print
 
    print "print 1 to 9"
    do
        print b
        b = b + 1
    loop until b = 10
 
  'examples using loop while
    print "print 1 to 3"
    a = 1
    do while a <= 3
        print a
        a = a + 1
    loop
    print
 
    print "print 9 to 7"
    b = 9
    do until b = 6
        print b
        b = b - 1
    loop
    print
 
    print "don't print anything"
    do while c = 10
        print c
        c = c + 1
    loop
 
    end
 
 


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/