<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.signature.net/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.signature.net/index.php?action=history&amp;feed=atom&amp;title=IB_Statements%2Fdo</id>
		<title>IB Statements/do - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.signature.net/index.php?action=history&amp;feed=atom&amp;title=IB_Statements%2Fdo"/>
		<link rel="alternate" type="text/html" href="http://wiki.signature.net/index.php?title=IB_Statements/do&amp;action=history"/>
		<updated>2026-04-08T13:26:29Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://wiki.signature.net/index.php?title=IB_Statements/do&amp;diff=363&amp;oldid=prev</id>
		<title>Badge: New page: '''DO statement'''   '''Syntax:'''  DO {WHILE | UNTIL} relational-expression  [conditional statement block]  LOOP  (or)  DO  [statement block]  LOOP {WHILE | UNTIL} relational-expression  ...</title>
		<link rel="alternate" type="text/html" href="http://wiki.signature.net/index.php?title=IB_Statements/do&amp;diff=363&amp;oldid=prev"/>
				<updated>2009-05-20T11:22:43Z</updated>
		
		<summary type="html">&lt;p&gt;New page: &amp;#39;&amp;#39;&amp;#39;DO statement&amp;#39;&amp;#39;&amp;#39;   &amp;#39;&amp;#39;&amp;#39;Syntax:&amp;#39;&amp;#39;&amp;#39;  DO {WHILE | UNTIL} relational-expression  [conditional statement block]  LOOP  (or)  DO  [statement block]  LOOP {WHILE | UNTIL} relational-expression  ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''DO statement''' &lt;br /&gt;
&lt;br /&gt;
'''Syntax:'''  DO {WHILE | UNTIL} relational-expression&lt;br /&gt;
&lt;br /&gt;
[conditional statement block]&lt;br /&gt;
&lt;br /&gt;
LOOP&lt;br /&gt;
&lt;br /&gt;
(or)&lt;br /&gt;
&lt;br /&gt;
DO&lt;br /&gt;
&lt;br /&gt;
[statement block]&lt;br /&gt;
&lt;br /&gt;
LOOP {WHILE | UNTIL} relational-expression&lt;br /&gt;
&lt;br /&gt;
(or)&lt;br /&gt;
&lt;br /&gt;
DO&lt;br /&gt;
&lt;br /&gt;
[statement block]&lt;br /&gt;
&lt;br /&gt;
LOOP&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
'''Discussion:'''  The DO and LOOP statements execute a block of code repeatedly, either (1) while a specified condition is true, or (2) until a specified condition is true. &lt;br /&gt;
&lt;br /&gt;
The relational expression may be any expression containing relational operations such that it can be evaluated as true or false. (For more information, see the IF/THEN discussion.) &lt;br /&gt;
&lt;br /&gt;
'''DO/WHILE''' will evaluate the relational expression and execute the statement block if the expression is true. At the LOOP statement, control returns to the expression evaluation. &lt;br /&gt;
&lt;br /&gt;
'''DO/UNTIL''' functions in the same manner, except that the code is executed if the expression is not true. In both cases, the evaluation of the expression is at the top of the loop. &lt;br /&gt;
&lt;br /&gt;
'''DO''' followed by '''LOOP/WHILE''' or '''LOOP/UNTIL''' causes the statement block to be executed at least once, no matter whether the expression is true or false. The test occurs at the bottom of the loop, and the statement block is executed again if the expression is true, for the WHILE case, or false, for the UNTIL case. &lt;br /&gt;
&lt;br /&gt;
'''DO/LOOP''' with no conditional clause should be used with care. The test that determines whether the loop should be executed or not must occur in the code itself using the BREAK statement. &lt;br /&gt;
 &lt;br /&gt;
'''Example 1:'''&lt;br /&gt;
   DO WHILE TOTQUAN LT LIMIT&lt;br /&gt;
   TOTQUAN=TOTQUAN+QUAN&lt;br /&gt;
   GOSUB GETNXT&lt;br /&gt;
   LOOP&lt;br /&gt;
&lt;br /&gt;
Whenever TOTQUAN is greater than or equal to LIMIT, control will pass immediately to the statement following the LOOP statement. &lt;br /&gt;
The same result will occur if the first statement is: &lt;br /&gt;
&lt;br /&gt;
DO UNTIL TOTQUAN GE LIMIT&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
'''Example 2:'''&lt;br /&gt;
   DO&lt;br /&gt;
   TOTQUAN=TOTQUAN+QUAN&lt;br /&gt;
   GOSUB GETNXT&lt;br /&gt;
   LOOP WHILE TOTQUAN LT LIMIT&lt;br /&gt;
&lt;br /&gt;
(or)&lt;br /&gt;
&lt;br /&gt;
LOOP UNTIL TOTQUAN GE LIMIT&lt;br /&gt;
&lt;br /&gt;
In this example, the statement block is executed at least once.  &lt;br /&gt;
&lt;br /&gt;
'''Example 3:'''&lt;br /&gt;
  DO&lt;br /&gt;
  .&lt;br /&gt;
  IF X=25 [THEN] BREAK&lt;br /&gt;
  .&lt;br /&gt;
  LOOP&lt;br /&gt;
&lt;br /&gt;
In this example, the loop is terminated if the variable X equals 25.  &lt;br /&gt;
&lt;br /&gt;
'''Additional discussion:'''  The DO/LOOP structure encompasses several specialized keywords, including DO, LOOP, WHILE, UNTIL, BREAK, and CONTINUE. Of these, only two are required to define a loop: the DO statement at the beginning and the LOOP statement at the ending. &lt;br /&gt;
&lt;br /&gt;
Thus, a simple DO loop would look like this: &lt;br /&gt;
&lt;br /&gt;
  DO&lt;br /&gt;
  [statement block]&lt;br /&gt;
  LOOP&lt;br /&gt;
&lt;br /&gt;
This structure defines an &amp;quot;endless&amp;quot; loop, and should be used with care. The code to terminate such a loop would be contained in the statement block and would include the BREAK statement as a way to end the loop (more on this below). &lt;br /&gt;
&lt;br /&gt;
A more common approach is to include conditions for the loop. Internet Basic accomplishes this with the WHILE and UNTIL clauses. While most structured languages include these clauses for the DO statement only, we've implemented them for the DO statement and the LOOP statement. If you use a conditional clause on the DO statement, the condition is evaluated at the top of the loop. If you use a conditional clause on the LOOP statement, the condition is evaluated at the bottom of the loop, meaning that the statement block will be executed at least once. Note that a conditional clause may be used either with the DO statement or with the LOOP statement, but not with both statements in the same structure. &lt;br /&gt;
&lt;br /&gt;
For example, the WHILE clause can be used with the DO statement as follows: &lt;br /&gt;
&lt;br /&gt;
  DO WHILE relational-expression&lt;br /&gt;
  [conditional statement block]&lt;br /&gt;
  LOOP&lt;br /&gt;
&lt;br /&gt;
The conditional statement block will be executed as long as the relational expression is true. When the relational expression is false, the program will branch to the first statement following the LOOP statement. &lt;br /&gt;
On the other hand, the UNTIL clause will cause the execution of the conditional statement block as long as the relational-expression is false. When the relational expression is true, the program will branch to the first statement following the LOOP statement. The UNTIL syntax is: &lt;br /&gt;
&lt;br /&gt;
  DO UNTIL relational-expression&lt;br /&gt;
  [conditional statement block]&lt;br /&gt;
  LOOP&lt;br /&gt;
&lt;br /&gt;
As an alternative, either conditional clause may be used on the LOOP statement, as follows: &lt;br /&gt;
&lt;br /&gt;
  DO&lt;br /&gt;
  [statement block]&lt;br /&gt;
  LOOP WHILE relational-expression&lt;br /&gt;
&lt;br /&gt;
  (or)&lt;br /&gt;
&lt;br /&gt;
  DO&lt;br /&gt;
  [statement block]&lt;br /&gt;
  LOOP UNTIL relational-expression&lt;br /&gt;
&lt;br /&gt;
In both of these cases, the statement block will be executed at least once; the loop test is performed at the bottom of the loop. &lt;br /&gt;
&lt;br /&gt;
Two program control statements can be used to modify the statement execution sequence in a DO/LOOP structure. These statements are BREAK and CONTINUE. The BREAK statement stops execution of the conditional statement block within and passes control to the statement following the LOOP statement. For example: &lt;br /&gt;
&lt;br /&gt;
  DO WHILE I LE 10&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  IF A=I [THEN] BREAK      ! jump out of the loop&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  LOOP&lt;br /&gt;
&lt;br /&gt;
The CONTINUE statement passes control to the LOOP statement in a DO/LOOP structure. For example: &lt;br /&gt;
&lt;br /&gt;
  DO WHILE A LT 100&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  IF A=B&lt;br /&gt;
       CONTINUE     ! branch to the LOOP statement&lt;br /&gt;
  ELSE&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  ENDIF&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  LOOP&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The BREAK and CONTINUE statements may also be used in the FOR/NEXT structure. BREAK passes control to the statement following the NEXT statement, while CONTINUE passes control to the NEXT statement. &lt;br /&gt;
In addition, the BREAK statement may be used in the SELECT/CASE structure&lt;/div&gt;</summary>
		<author><name>Badge</name></author>	</entry>

	</feed>