2015-08-02 12:12:44 +00:00
|
|
|
The {{KW|WHILE...WEND}} statement is used to repeat a block of statements while the condition is met.
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
|
|
|
:{{KW|WHILE}} {{Parameter|condition}}
|
|
|
|
:.
|
|
|
|
:.
|
|
|
|
:.
|
|
|
|
:{{KW|WEND}}
|
|
|
|
|
|
|
|
|
|
|
|
{{PageDescription}}
|
|
|
|
* {{Parameter|condition}} is a numeric expression used to determine if the loop will execute.
|
|
|
|
* {{Parameter|statements}} will execute repeatedly while {{Parameter|condition}} is a non-zero value.
|
2021-02-28 14:47:33 +00:00
|
|
|
* [[EXIT WHILE]] can be used for emergency exits from the loop.
|
|
|
|
* Use [[_CONTINUE]] to skip the remaining lines in the iteration without leaving the loop.
|
2015-08-02 12:12:44 +00:00
|
|
|
* A [[DO...LOOP]] can use the same DO WHILE condition to get the same results.
|
|
|
|
* WHILE loops only run if the WHILE condition is True.
|
|
|
|
|
|
|
|
|
|
|
|
{{Template:RelationalTable}}
|
|
|
|
|
|
|
|
|
|
|
|
{{PageExamples}}
|
|
|
|
''Example 1:'' Reading an entire file. Example assumes the program has a [[OPEN|file opened]] as #1
|
|
|
|
|
|
|
|
{{CodeStart}} '' ''
|
2021-02-11 11:41:53 +00:00
|
|
|
{{Cl|OPEN}} "Readme.txt" {{Cl|FOR (file statement)|FOR}} {{Cl|INPUT}} {{Cl|AS}} #1
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|WHILE...WEND|WHILE}} {{Cl|NOT}} {{Cl|EOF}}(1)
|
|
|
|
{{Cl|_LIMIT}} 1 'limit line prints to one per second
|
|
|
|
{{Cl|LINE INPUT (file statement)|LINE INPUT #}}1, text$
|
2021-02-11 11:41:53 +00:00
|
|
|
{{Cl|IF}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) {{Cl|THEN}} {{Cl|EXIT WHILE}} 'ESC key exits
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|PRINT}} text$
|
|
|
|
{{Cl|WEND}} '' ''
|
|
|
|
{{CodeEnd}}
|
|
|
|
|
|
|
|
''Example 2:'' Clearing the keyboard buffer.
|
|
|
|
{{CodeStart}} '' ''
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|WHILE}} {{Cl|INKEY$}} <> "" : {{Cl|WEND}} '' ''
|
2015-08-02 12:12:44 +00:00
|
|
|
{{CodeEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSeeAlso}}
|
|
|
|
* [[DO...LOOP]]
|
|
|
|
* [[FOR...NEXT]]
|
|
|
|
* [[UNTIL]] (condition)
|
2017-10-10 14:55:21 +00:00
|
|
|
* [[_CONTINUE]]
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageNavigation}}
|