|
Do | |||
Do .. Loop | |||
Parameters: NONE | |||
Returns: NONE | |||
Do / Loop pairs in their most simplest form, are a way to create unconditional infinite loops. The Do represents the start or entry point of a section of code that is to be repeated, while the loop acts as the jump back to start instruction, telling the PlayBASIC to jump back to the preceding matching do instruction. So when a Do-Loop is executed, PlayBASIC will run any code placed inside the Do / Loop pair infinitely. Do / Loop pairs can also be used to created conditional loops by placing a conditional expression after either the Do or Loop statements. Placing an expression after the Do creates a While-EndWhile replacement, placing an expression after loop turns it into a Repeat- Until substitute. FACTS: * Do / Loop's must be paired. * Do & Loop statements may contain conditional expressions (See example bellow). * The Do must proceed the Loop statement. You'll get an error otherwise. * None conditional Do / Loops will repeat a section of code forever, or until the Loop is broken, via Exit or ExitDo. Users can manually break the execution of the Do/Loop by pressing the ESCape key or clicking the Window Close [X] gadget in windowed program. It may take runtime enviroment a while to respond however, in locked up a program. * Not sure about loops ? Make sure you read the Loops tutorial then Mini Tutorial #1: In this example, we see a Do-Loop being used to keep the program constantly running. This code will randomly draw dots to the screen. It will Do so, until the program is interrupted, by either the break key (ESC key) or clicking upon the close gadget on the window.
To examine more closely what's happening, lets step through the logic that this piece of code is telling PlayBASIC to perform.
Mini Tutorial #2: In this example, we see a conditional Do-Loop being used to keep the program constantly running. The program uses the computers Timer() value to execute the code within the Do-Loop structured for a period of 5 seconds (5000 milliseconds). Once that time is up, PlayBASIC exits the Do-Loop and continues on. Making a conditional Do-Loop the equivalent of While/EndWhile loop.
|
Related Info: | Comparisons | Continue | DecLoop | Exit | ExitDo | For | Loop | Loops | Repeat | While : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |