1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir
3cdf0e10cSrcweir
4*d33d0967SAndrew Rist<!--***********************************************************
5*d33d0967SAndrew Rist *
6*d33d0967SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
7*d33d0967SAndrew Rist * or more contributor license agreements.  See the NOTICE file
8*d33d0967SAndrew Rist * distributed with this work for additional information
9*d33d0967SAndrew Rist * regarding copyright ownership.  The ASF licenses this file
10*d33d0967SAndrew Rist * to you under the Apache License, Version 2.0 (the
11*d33d0967SAndrew Rist * "License"); you may not use this file except in compliance
12*d33d0967SAndrew Rist * with the License.  You may obtain a copy of the License at
13*d33d0967SAndrew Rist *
14*d33d0967SAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
15*d33d0967SAndrew Rist *
16*d33d0967SAndrew Rist * Unless required by applicable law or agreed to in writing,
17*d33d0967SAndrew Rist * software distributed under the License is distributed on an
18*d33d0967SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*d33d0967SAndrew Rist * KIND, either express or implied.  See the License for the
20*d33d0967SAndrew Rist * specific language governing permissions and limitations
21*d33d0967SAndrew Rist * under the License.
22*d33d0967SAndrew Rist *
23*d33d0967SAndrew Rist ***********************************************************-->
24*d33d0967SAndrew Rist
25*d33d0967SAndrew Rist
26cdf0e10cSrcweir
27cdf0e10cSrcweir<helpdocument version="1.0">
28cdf0e10cSrcweir<meta>
29cdf0e10cSrcweir<topic id="textsbasicshared03090201xml" indexer="include" status="PUBLISH">
30cdf0e10cSrcweir<title id="tit" xml-lang="en-US">Do...Loop Statement [Runtime]</title>
31cdf0e10cSrcweir<filename>/text/sbasic/shared/03090201.xhp</filename>
32cdf0e10cSrcweir</topic>
33cdf0e10cSrcweir<history>
34cdf0e10cSrcweir<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
35cdf0e10cSrcweir<lastedited date="2004-08-24T13:30:35">converted from old format - fpe</lastedited>
36cdf0e10cSrcweir</history>
37cdf0e10cSrcweir</meta>
38cdf0e10cSrcweir<body>
39cdf0e10cSrcweir<section id="doloop">
40cdf0e10cSrcweir<bookmark xml-lang="en-US" branch="index" id="bm_id3156116"><bookmark_value>Do...Loop statement</bookmark_value>
41cdf0e10cSrcweir<bookmark_value>While; Do loop</bookmark_value>
42cdf0e10cSrcweir<bookmark_value>Until</bookmark_value>
43cdf0e10cSrcweir<bookmark_value>loops</bookmark_value>
44cdf0e10cSrcweir</bookmark>
45cdf0e10cSrcweir<paragraph role="heading" id="hd_id3156116" xml-lang="en-US" level="1" l10n="U" oldref="1"><link href="text/sbasic/shared/03090201.xhp" name="Do...Loop Statement [Runtime]">Do...Loop Statement [Runtime]</link></paragraph>
46cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3109850" xml-lang="en-US" l10n="U" oldref="2">Repeats the statements between the Do and the Loop statement while the condition is True or until the condition becomes True.</paragraph>
47cdf0e10cSrcweir</section>
48cdf0e10cSrcweir<paragraph role="heading" id="hd_id3149119" xml-lang="en-US" level="2" l10n="U" oldref="3">Syntax</paragraph>
49cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3155150" xml-lang="en-US" l10n="U" oldref="4">Do [{While | Until} condition = True]</paragraph>
50cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3154422" xml-lang="en-US" l10n="U" oldref="5">statement block</paragraph>
51cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3150789" xml-lang="en-US" l10n="U" oldref="6">[Exit Do]</paragraph>
52cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3155805" xml-lang="en-US" l10n="U" oldref="7">statement block</paragraph>
53cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3145090" xml-lang="en-US" l10n="U" oldref="8">Loop</paragraph>
54cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3154749" xml-lang="en-US" l10n="U" oldref="9">or</paragraph>
55cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3150503" xml-lang="en-US" l10n="U" oldref="10">Do</paragraph>
56cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149762" xml-lang="en-US" l10n="U" oldref="11">statement block</paragraph>
57cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3150984" xml-lang="en-US" l10n="U" oldref="12">[Exit Do]</paragraph>
58cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3143228" xml-lang="en-US" l10n="U" oldref="13">statement block</paragraph>
59cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149235" xml-lang="en-US" l10n="U" oldref="14">Loop [{While | Until} condition = True]</paragraph>
60cdf0e10cSrcweir<paragraph role="heading" id="hd_id3156024" xml-lang="en-US" level="2" l10n="U" oldref="15">Parameters/Elements</paragraph>
61cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3156344" xml-lang="en-US" l10n="U" oldref="16">
62cdf0e10cSrcweir<emph>Condition:</emph> A comparison, numeric or string expression, that evaluates either True or False.</paragraph>
63cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149669" xml-lang="en-US" l10n="U" oldref="17">
64cdf0e10cSrcweir<emph>Statement block:</emph> Statements that you want to repeat while or until the condition is True.</paragraph>
65cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3150791" xml-lang="en-US" l10n="U" oldref="18">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>
66cdf0e10cSrcweir<paragraph role="heading" id="hd_id3154366" xml-lang="en-US" level="2" l10n="U" oldref="19">Syntax</paragraph>
67cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3145171" xml-lang="en-US" l10n="U" oldref="20">Do While condition = True</paragraph>
68cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149203" xml-lang="en-US" l10n="U" oldref="21">...statement block</paragraph>
69cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3125864" xml-lang="en-US" l10n="U" oldref="22">Loop</paragraph>
70cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3154124" xml-lang="en-US" l10n="U" oldref="24">The statement block between the Do While and the Loop statements is repeated so long as the condition is true.</paragraph>
71cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3153968" xml-lang="en-US" l10n="U" oldref="25">Do Until condition = True</paragraph>
72cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3154909" xml-lang="en-US" l10n="U" oldref="26">...statement block</paragraph>
73cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3159151" xml-lang="en-US" l10n="U" oldref="27">Loop</paragraph>
74cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3150440" xml-lang="en-US" l10n="U" oldref="29">The statement block between the Do Until and the Loop statements is repeated if the condition so long as the condition is false.</paragraph>
75cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3153952" xml-lang="en-US" l10n="U" oldref="30">Do</paragraph>
76cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3147349" xml-lang="en-US" l10n="U" oldref="31">...statement block</paragraph>
77cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3159153" xml-lang="en-US" l10n="U" oldref="32">Loop While condition = True</paragraph>
78cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3146985" xml-lang="en-US" l10n="U" oldref="34">The statement block between the Do and the Loop statements repeats so long as the condition is true.</paragraph>
79cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3150488" xml-lang="en-US" l10n="U" oldref="35">Do</paragraph>
80cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3153189" xml-lang="en-US" l10n="U" oldref="36">...statement block</paragraph>
81cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3155411" xml-lang="en-US" l10n="U" oldref="37">Loop Until condition = True</paragraph>
82cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3151117" xml-lang="en-US" l10n="U" oldref="39">The statement block between the Do and the Loop statements repeats until the condition is true.</paragraph>
83cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149484" xml-lang="en-US" l10n="U" oldref="41">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>
84cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149262" xml-lang="en-US" l10n="U" oldref="42">Do...</paragraph>
85cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3149298" xml-lang="en-US" l10n="U" oldref="43">statements</paragraph>
86cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3145646" xml-lang="en-US" l10n="U" oldref="44">If condition = True Then Exit Do</paragraph>
87cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3154490" xml-lang="en-US" l10n="U" oldref="45">statements</paragraph>
88cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3153159" xml-lang="en-US" l10n="U" oldref="46">Loop...</paragraph>
89cdf0e10cSrcweir<paragraph role="heading" id="hd_id3147396" xml-lang="en-US" level="2" l10n="U" oldref="47">Example</paragraph>
90cdf0e10cSrcweir<paragraph role="code" id="par_id3144764" xml-lang="en-US" l10n="U" oldref="49">Sub ExampleDoLoop</paragraph>
91cdf0e10cSrcweir<paragraph role="code" id="par_id3154791" xml-lang="en-US" l10n="U" oldref="50">Dim sFile As String</paragraph>
92cdf0e10cSrcweir<paragraph role="code" id="par_id3149401" xml-lang="en-US" l10n="U" oldref="51">Dim sPath As String</paragraph>
93cdf0e10cSrcweir<paragraph role="code" id="par_id3155600" xml-lang="en-US" l10n="U" oldref="52">sPath = "c:\"</paragraph>
94cdf0e10cSrcweir<paragraph role="code" id="par_id3150717" xml-lang="en-US" l10n="U" oldref="53">sFile = Dir$( sPath ,22)</paragraph>
95cdf0e10cSrcweir<paragraph role="code" id="par_id3146898" xml-lang="en-US" l10n="U" oldref="54">If sFile &lt;&gt; "" Then</paragraph>
96cdf0e10cSrcweir<paragraph role="code" id="par_id3156333" xml-lang="en-US" l10n="U" oldref="55">Do</paragraph>
97cdf0e10cSrcweir<paragraph role="code" id="par_id3153947" xml-lang="en-US" l10n="U" oldref="56">MsgBox sFile</paragraph>
98cdf0e10cSrcweir<paragraph role="code" id="par_id3150327" xml-lang="en-US" l10n="U" oldref="57">sFile = Dir$</paragraph>
99cdf0e10cSrcweir<paragraph role="code" id="par_id3150749" xml-lang="en-US" l10n="U" oldref="58">Loop Until sFile = ""</paragraph>
100cdf0e10cSrcweir<paragraph role="code" id="par_id3153765" xml-lang="en-US" l10n="U" oldref="59">End If</paragraph>
101cdf0e10cSrcweir<paragraph role="code" id="par_id3148914" xml-lang="en-US" l10n="U" oldref="60">End Sub</paragraph>
102cdf0e10cSrcweir</body>
103cdf0e10cSrcweir</helpdocument>
104