home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2002 #3 / K-CD-3-2002.ISO / OpenOffice / f_0046 / sbasic.jar / text / sbasic / common / 03090201.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-09-07  |  6.5 KB  |  76 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Do...Loop Statement [Runtime]</title><meta name="filename" content="text/sbasic/common/03090201"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         span.T1{
  7.                 font-weight:bold;}
  8.         </style></head><body>
  9.   
  10.   
  11.   <help:to-be-embedded Eid="doloop" xmlns:help="http://openoffice.org/2000/help"><a name="doloop"/>
  12.   <p class="Head1"><help:link Id="66463">Do...Loop Statement [Runtime]</help:link></p>
  13.   <p class="Paragraph">Repeats the statements between the Do and the Loop statement while the condition is True or until the condition becomes True.</p>
  14.   </help:to-be-embedded>
  15.   <p class="Paragraph"><span class="T1">Syntax</span></p>
  16.   <p class="Paragraph"><help:key-word value="Do" tag="kw66463_1" xmlns:help="http://openoffice.org/2000/help"/>Do [{<help:key-word value="While" tag="kw66463_4" xmlns:help="http://openoffice.org/2000/help"/>While | <help:key-word value="Until" tag="kw66463_3" xmlns:help="http://openoffice.org/2000/help"/>Until} condition = True]</p>
  17.   <p class="Paragraph">statement block</p>
  18.   <p class="Paragraph"><span class="T1">[Exit Do]</span></p>
  19.   <p class="Paragraph">statement block</p>
  20.   <p class="Paragraph"><help:key-word value="Loop" tag="kw66463_2" xmlns:help="http://openoffice.org/2000/help"/>Loop</p>
  21.   <p class="Paragraph">or</p>
  22.   <p class="Paragraph">Do</p>
  23.   <p class="Paragraph">statement block</p>
  24.   <p class="Paragraph">[Exit Do]</p>
  25.   <p class="Paragraph">statement block</p>
  26.   <p class="Paragraph">Loop [{While | Until} condition = True]</p>
  27.   <p class="Paragraph"><span class="T1">Param./Element</span></p>
  28.   <p class="Paragraph">Condition: A comparison, numeric or string expression that evaluates either True or False.</p>
  29.   <p class="Paragraph">Statement block: Statements to be repeated while or until the condition is True.</p>
  30.   <p class="Paragraph"><span class="T1">The Do...Loop statement is used to execute a loop as long as (or until) a certain condition is True. The condition for exiting the loop must be entered following either the Do or the Loop statement. The following examples are valid combinations:</span></p>
  31.   <p class="Paragraph"><span class="T1">Syntax</span></p>
  32.   <p class="Paragraph">Do While condition = True</p>
  33.   <p class="Paragraph">...statement block</p>
  34.   <p class="Paragraph"><span class="T1">Loop</span></p>
  35.   <p class="Paragraph">The program tests the condition. If the condition is False, the program continues directly after the <span class="T1">Loop</span> statement. If the condition is True, the <span class="T1">loop</span> is activated, and the program jumps back to the <span class="T1">Do</span> statement. If the condition is still True, the loop will be repeated, otherwise the program execution continues with the statement following the <span class="T1">Loop</span> statement.</p>
  36.   <p class="Paragraph">To summarize: The loop will be repeated as long as the condition is true.</p>
  37.   <p class="Paragraph">Do Until condition = True</p>
  38.   <p class="Paragraph">...statement block</p>
  39.   <p class="Paragraph">Loop</p>
  40.   <p class="Paragraph">The program tests the condition. If the condition is True, the program continues directly after the <span class="T1">Loop</span> statement. If the condition is not True, the <span class="T1">loop</span> is activated, and the program jumps back to the <span class="T1">Do</span> statement. If the condition is still not True, the loop will be repeated, otherwise the program execution continues with the statement following the <span class="T1">Loop</span> statement.</p>
  41.   <p class="Paragraph">To summarize: The loop will only be repeated, if the condition is False at first, and then until the condition becomes true.</p>
  42.   <p class="Paragraph">Do</p>
  43.   <p class="Paragraph">...statement block</p>
  44.   <p class="Paragraph">Loop While condition = True</p>
  45.   <p class="Paragraph">The program initiates the loop immediately. At the <span class="T1">Loop</span> statement, the condition is tested. If the condition is True, the program repeats the loop starting from the <span class="T1">Do</span> statement. Only when the condition following <span class="T1">Loop</span> becomes False,the program will end the loop.</p>
  46.   <p class="Paragraph">To summarize: The statements within the loop will be executed once in each case, and as long as the condition is true.</p>
  47.   <p class="Paragraph">Do</p>
  48.   <p class="Paragraph">...statement block</p>
  49.   <p class="Paragraph">Loop Until condition = True</p>
  50.   <p class="Paragraph">The program initiates the loop immediately. At the <span class="T1">Loop</span> statement, the condition is tested. If the condition is not True, the program repeats the loop starting from the <span class="T1">Do</span> statement. Only when the condition following <span class="T1">Loop</span> becomes True, the program will end the loop.</p>
  51.   <p class="Paragraph">To summarize: The statements within the loop will be executed once in each case, and until the condition becomes true.</p>
  52.   <p class="Paragraph">The main difference between the above mentioned statements is that in the first two cases, the loop is initiated dependent on the condition. In the last two examples, the statements between <span class="T1">Do</span> und <span class="T1">Loop</span> are executed once at least.</p>
  53.   <p class="Paragraph">The <span class="T1">Exit Do</span> statement ends the loop unconditionally. This statement is placed anywhere within a <span class="T1">Do</span>...<span class="T1">Loop</span> statement. You can define an exit condition using the <span class="T1">If...Then</span> structure as follows:</p>
  54.   <p class="Paragraph">Do...</p>
  55.   <p class="Paragraph">statements</p>
  56.   <p class="Paragraph">If condition = True Then Exit Do</p>
  57.   <p class="Paragraph">statements</p>
  58.   <p class="Paragraph">Loop...</p>
  59.   <p class="Paragraph"><span class="T1">Example</span></p>
  60.   <p class="Paragraph"/>
  61.   <p class="Paragraph">Sub ExampleDoLoop</p>
  62.   <p class="Paragraph">Dim sFile As String</p>
  63.   <p class="PropText">Dim sPath As String</p>
  64.   <p class="PropText">sPath = "c:\"</p>
  65.   <p class="PropText">sFile = Dir$( sPath ,22)</p>
  66.   <p class="PropText">If sFile <> "" Then</p>
  67.   <p class="PropText">Do</p>
  68.   <p class="PropText">MsgBox sFile</p>
  69.   <p class="PropText">sFile = Dir$</p>
  70.   <p class="PropText">Loop Until sFile = ""</p>
  71.   <p class="PropText">End If</p>
  72.   <p class="PropText">End Sub</p>
  73.   <p class="PropText"/>
  74.   <p class="PropText"/>
  75.   <p class="PropText"/>
  76.  </body></html>