DO-LOOP/de
Aus MCS Wiki AVR
Inhaltsverzeichnis |
Action
Wiederholt einen Block von Befehlen bis die Bedingung wahr ist.
Syntax
DO
statements
LOOP [ UNTIL expression]
Anmerkungen
Man kann eine DO..LOOP mit EXIT DO verlassen.
Die DO-LOOP Schleife wird immer mindestens einmal ausgeführt.
Der Haupt-Teil eines BASCOM-Programms sollte normalerweise in einer DO..LOOP Endlosschleife ausgeführt werden.
Man könnte auch GOTO benutzen aber das ist nicht so klar wie DO..LOOP.
Main:
'Code
GOTO Main
Do
'Code
Loop
Natürlich ist es im obigen Beispiel einfach, zu sehen was passiert aber wenn das Programm aus vielen Zeilen Code besteht dann ist es nicht mehr so klar was GOTO Main bewirken soll.
Siehe auch
EXIT , WHILE-WEND , FOR-NEXT
Beispiel
'----------------------------------------------------------------------------------------- 'name : do_loop.bas 'copyright : (c) 1995-2005, MCS Electronics 'purpose : demo: DO, LOOP 'micro : Mega48 'suited for demo : yes 'commercial addon needed : no '----------------------------------------------------------------------------------------- $regfile = "m48def.dat" ' specify the used micro $crystal = 4000000 ' used crystal frequency $baud = 19200 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space Dim A As Byte A = 1 'assign a var Do 'begin a do..loop Print A 'print var Incr A 'increase by one Loop Until A = 10 'do until a=10 End 'You can write a never-ending loop with the following code Do 'Your code goes here Loop
Languages | English • Deutsch |
---|