blob: ff72a47bf76e5883b97f30081b53fd09bf151110 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--***********************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
***********************************************************-->
<helpdocument version="1.0">
<meta>
<topic id="textsbasicshared03090201xml" indexer="include" status="PUBLISH">
<title id="tit" xml-lang="en-US">Do...Loop Statement [Runtime]</title>
<filename>/text/sbasic/shared/03090201.xhp</filename>
</topic>
</meta>
<body>
<section id="doloop">
<bookmark xml-lang="en-US" branch="index" id="bm_id3156116">
<bookmark_value>Do...Loop statement</bookmark_value>
<bookmark_value>While; Do loop</bookmark_value>
<bookmark_value>Until</bookmark_value>
<bookmark_value>loops</bookmark_value>
</bookmark>
<paragraph role="heading" id="hd_id3156116" xml-lang="en-US" level="1" l10n="U"><link href="text/sbasic/shared/03090201.xhp" name="Do...Loop Statement [Runtime]">Do...Loop Statement [Runtime]</link></paragraph>
<paragraph role="paragraph" id="par_id3109850" xml-lang="en-US" l10n="U">Repeats the statements between the Do and the Loop statement while the condition is True or until the condition becomes True.</paragraph>
</section>
<paragraph role="heading" id="hd_id3149119" xml-lang="en-US" level="2" l10n="U">Syntax</paragraph>
<paragraph role="paragraph" id="par_id3155150" xml-lang="en-US" l10n="U">Do [{While | Until} condition = True]</paragraph>
<paragraph role="paragraph" id="par_id3154422" xml-lang="en-US" l10n="U">statement block</paragraph>
<paragraph role="paragraph" id="par_id3150789" xml-lang="en-US" l10n="U">[Exit Do]</paragraph>
<paragraph role="paragraph" id="par_id3155805" xml-lang="en-US" l10n="U">statement block</paragraph>
<paragraph role="paragraph" id="par_id3145090" xml-lang="en-US" l10n="U">Loop</paragraph>
<paragraph role="paragraph" id="par_id3154749" xml-lang="en-US" l10n="U">or</paragraph>
<paragraph role="paragraph" id="par_id3150503" xml-lang="en-US" l10n="U">Do</paragraph>
<paragraph role="paragraph" id="par_id3149762" xml-lang="en-US" l10n="U">statement block</paragraph>
<paragraph role="paragraph" id="par_id3150984" xml-lang="en-US" l10n="U">[Exit Do]</paragraph>
<paragraph role="paragraph" id="par_id3143228" xml-lang="en-US" l10n="U">statement block</paragraph>
<paragraph role="paragraph" id="par_id3149235" xml-lang="en-US" l10n="U">Loop [{While | Until} condition = True]</paragraph>
<paragraph role="heading" id="hd_id3156024" xml-lang="en-US" level="2" l10n="U">Parameters/Elements</paragraph>
<paragraph role="paragraph" id="par_id3156344" xml-lang="en-US" l10n="U"><emph>Condition:</emph> A comparison, numeric or string expression, that evaluates either True or False.</paragraph>
<paragraph role="paragraph" id="par_id3149669" xml-lang="en-US" l10n="U"><emph>Statement block:</emph> Statements that you want to repeat while or until the condition is True.</paragraph>
<paragraph role="paragraph" id="par_id3150791" xml-lang="en-US" l10n="U">The <emph>Do...Loop</emph> statement executes a loop as long as, or until, a certain condition is True. The condition for exiting the loop must be entered following either the <emph>Do</emph> or the <emph>Loop</emph> statement. The following examples are valid combinations:</paragraph>
<paragraph role="heading" id="hd_id3154366" xml-lang="en-US" level="2" l10n="U">Syntax</paragraph>
<paragraph role="paragraph" id="par_id3145171" xml-lang="en-US" l10n="U">Do While condition = True</paragraph>
<paragraph role="paragraph" id="par_id3149203" xml-lang="en-US" l10n="U">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3125864" xml-lang="en-US" l10n="U">Loop</paragraph>
<paragraph role="paragraph" id="par_id3154124" xml-lang="en-US" l10n="U">The statement block between the Do While and the Loop statements is repeated so long as the condition is true.</paragraph>
<paragraph role="paragraph" id="par_id3153968" xml-lang="en-US" l10n="U">Do Until condition = True</paragraph>
<paragraph role="paragraph" id="par_id3154909" xml-lang="en-US" l10n="U">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3159151" xml-lang="en-US" l10n="U">Loop</paragraph>
<paragraph role="paragraph" id="par_id3150440" xml-lang="en-US" l10n="U">The statement block between the Do Until and the Loop statements is repeated if the condition so long as the condition is false.</paragraph>
<paragraph role="paragraph" id="par_id3153952" xml-lang="en-US" l10n="U">Do</paragraph>
<paragraph role="paragraph" id="par_id3147349" xml-lang="en-US" l10n="U">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3159153" xml-lang="en-US" l10n="U">Loop While condition = True</paragraph>
<paragraph role="paragraph" id="par_id3146985" xml-lang="en-US" l10n="U">The statement block between the Do and the Loop statements repeats so long as the condition is true.</paragraph>
<paragraph role="paragraph" id="par_id3150488" xml-lang="en-US" l10n="U">Do</paragraph>
<paragraph role="paragraph" id="par_id3153189" xml-lang="en-US" l10n="U">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3155411" xml-lang="en-US" l10n="U">Loop Until condition = True</paragraph>
<paragraph role="paragraph" id="par_id3151117" xml-lang="en-US" l10n="U">The statement block between the Do and the Loop statements repeats until the condition is true.</paragraph>
<paragraph role="paragraph" id="par_id3149484" xml-lang="en-US" l10n="U">Use the <emph>Exit Do</emph> statement to unconditionally end the loop. You can add this statement anywhere in a <emph>Do</emph>...<emph>Loop</emph> statement. You can also define an exit condition using the <emph>If...Then</emph> structure as follows:</paragraph>
<paragraph role="paragraph" id="par_id3149262" xml-lang="en-US" l10n="U">Do...</paragraph>
<paragraph role="paragraph" id="par_id3149298" xml-lang="en-US" l10n="U">statements</paragraph>
<paragraph role="paragraph" id="par_id3145646" xml-lang="en-US" l10n="U">If condition = True Then Exit Do</paragraph>
<paragraph role="paragraph" id="par_id3154490" xml-lang="en-US" l10n="U">statements</paragraph>
<paragraph role="paragraph" id="par_id3153159" xml-lang="en-US" l10n="U">Loop...</paragraph>
<paragraph role="heading" id="hd_id3147396" xml-lang="en-US" level="2" l10n="U">Example</paragraph>
<paragraph role="code" id="par_id3144764" xml-lang="en-US" l10n="U">Sub ExampleDoLoop</paragraph>
<paragraph role="code" id="par_id3154791" xml-lang="en-US" l10n="U">Dim sFile As String</paragraph>
<paragraph role="code" id="par_id3149401" xml-lang="en-US" l10n="U">Dim sPath As String</paragraph>
<paragraph role="code" id="par_id3155600" xml-lang="en-US" l10n="U">sPath = "c:\"</paragraph>
<paragraph role="code" id="par_id3150717" xml-lang="en-US" l10n="U">sFile = Dir$( sPath ,22)</paragraph>
<paragraph role="code" id="par_id3146898" xml-lang="en-US" l10n="U">If sFile &lt;&gt; "" Then</paragraph>
<paragraph role="code" id="par_id3156333" xml-lang="en-US" l10n="U">Do</paragraph>
<paragraph role="code" id="par_id3153947" xml-lang="en-US" l10n="U">MsgBox sFile</paragraph>
<paragraph role="code" id="par_id3150327" xml-lang="en-US" l10n="U">sFile = Dir$</paragraph>
<paragraph role="code" id="par_id3150749" xml-lang="en-US" l10n="U">Loop Until sFile = ""</paragraph>
<paragraph role="code" id="par_id3153765" xml-lang="en-US" l10n="U">End If</paragraph>
<paragraph role="code" id="par_id3148914" xml-lang="en-US" l10n="U">End Sub</paragraph>
</body>
</helpdocument>