|
Loop | |||
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 running program 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 infinitely. Do / Loop pairs can also be used to created conditional loops by placing a conditional expression after either the Do or Loop statements. FACTS: * Do / Loops must be paired. * The Do must preceed the Loop statement. You'll get an error optherwise. * None conditional Do / Loops will repeat a section of code forever, or until the loop is broken. Eg via EXIT or EXITDO * Not sure about loops ? Make sure you read the Loops tutorial! Mini Tutorial #1: In this example, we see a Do-Loop being used to keep the program constantly running. This cde 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: | Continue | Do | Exit | ExitDo | For | Loops | Repeat | While : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |