summaryrefslogtreecommitdiff
path: root/helpcontent2/source/text/sbasic/shared/03090201.xhp
blob: e3a08323c7d03a791501f0519b22df7a698742dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?xml version="1.0" encoding="UTF-8"?>


<!--***********************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 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>
<history>
<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
<lastedited date="2004-08-24T13:30:35">converted from old format - fpe</lastedited>
</history>
</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" oldref="1"><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" oldref="2">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" oldref="3">Syntax</paragraph>
<paragraph role="paragraph" id="par_id3155150" xml-lang="en-US" l10n="U" oldref="4">Do [{While | Until} condition = True]</paragraph>
<paragraph role="paragraph" id="par_id3154422" xml-lang="en-US" l10n="U" oldref="5">statement block</paragraph>
<paragraph role="paragraph" id="par_id3150789" xml-lang="en-US" l10n="U" oldref="6">[Exit Do]</paragraph>
<paragraph role="paragraph" id="par_id3155805" xml-lang="en-US" l10n="U" oldref="7">statement block</paragraph>
<paragraph role="paragraph" id="par_id3145090" xml-lang="en-US" l10n="U" oldref="8">Loop</paragraph>
<paragraph role="paragraph" id="par_id3154749" xml-lang="en-US" l10n="U" oldref="9">or</paragraph>
<paragraph role="paragraph" id="par_id3150503" xml-lang="en-US" l10n="U" oldref="10">Do</paragraph>
<paragraph role="paragraph" id="par_id3149762" xml-lang="en-US" l10n="U" oldref="11">statement block</paragraph>
<paragraph role="paragraph" id="par_id3150984" xml-lang="en-US" l10n="U" oldref="12">[Exit Do]</paragraph>
<paragraph role="paragraph" id="par_id3143228" xml-lang="en-US" l10n="U" oldref="13">statement block</paragraph>
<paragraph role="paragraph" id="par_id3149235" xml-lang="en-US" l10n="U" oldref="14">Loop [{While | Until} condition = True]</paragraph>
<paragraph role="heading" id="hd_id3156024" xml-lang="en-US" level="2" l10n="U" oldref="15">Parameters/Elements</paragraph>
<paragraph role="paragraph" id="par_id3156344" xml-lang="en-US" l10n="U" oldref="16">
<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" oldref="17">
<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" 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>
<paragraph role="heading" id="hd_id3154366" xml-lang="en-US" level="2" l10n="U" oldref="19">Syntax</paragraph>
<paragraph role="paragraph" id="par_id3145171" xml-lang="en-US" l10n="U" oldref="20">Do While condition = True</paragraph>
<paragraph role="paragraph" id="par_id3149203" xml-lang="en-US" l10n="U" oldref="21">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3125864" xml-lang="en-US" l10n="U" oldref="22">Loop</paragraph>
<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>
<paragraph role="paragraph" id="par_id3153968" xml-lang="en-US" l10n="U" oldref="25">Do Until condition = True</paragraph>
<paragraph role="paragraph" id="par_id3154909" xml-lang="en-US" l10n="U" oldref="26">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3159151" xml-lang="en-US" l10n="U" oldref="27">Loop</paragraph>
<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>
<paragraph role="paragraph" id="par_id3153952" xml-lang="en-US" l10n="U" oldref="30">Do</paragraph>
<paragraph role="paragraph" id="par_id3147349" xml-lang="en-US" l10n="U" oldref="31">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3159153" xml-lang="en-US" l10n="U" oldref="32">Loop While condition = True</paragraph>
<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>
<paragraph role="paragraph" id="par_id3150488" xml-lang="en-US" l10n="U" oldref="35">Do</paragraph>
<paragraph role="paragraph" id="par_id3153189" xml-lang="en-US" l10n="U" oldref="36">...statement block</paragraph>
<paragraph role="paragraph" id="par_id3155411" xml-lang="en-US" l10n="U" oldref="37">Loop Until condition = True</paragraph>
<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>
<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>
<paragraph role="paragraph" id="par_id3149262" xml-lang="en-US" l10n="U" oldref="42">Do...</paragraph>
<paragraph role="paragraph" id="par_id3149298" xml-lang="en-US" l10n="U" oldref="43">statements</paragraph>
<paragraph role="paragraph" id="par_id3145646" xml-lang="en-US" l10n="U" oldref="44">If condition = True Then Exit Do</paragraph>
<paragraph role="paragraph" id="par_id3154490" xml-lang="en-US" l10n="U" oldref="45">statements</paragraph>
<paragraph role="paragraph" id="par_id3153159" xml-lang="en-US" l10n="U" oldref="46">Loop...</paragraph>
<paragraph role="heading" id="hd_id3147396" xml-lang="en-US" level="2" l10n="U" oldref="47">Example</paragraph>
<paragraph role="code" id="par_id3144764" xml-lang="en-US" l10n="U" oldref="49">Sub ExampleDoLoop</paragraph>
<paragraph role="code" id="par_id3154791" xml-lang="en-US" l10n="U" oldref="50">Dim sFile As String</paragraph>
<paragraph role="code" id="par_id3149401" xml-lang="en-US" l10n="U" oldref="51">Dim sPath As String</paragraph>
<paragraph role="code" id="par_id3155600" xml-lang="en-US" l10n="U" oldref="52">sPath = "c:\"</paragraph>
<paragraph role="code" id="par_id3150717" xml-lang="en-US" l10n="U" oldref="53">sFile = Dir$( sPath ,22)</paragraph>
<paragraph role="code" id="par_id3146898" xml-lang="en-US" l10n="U" oldref="54">If sFile &lt;&gt; "" Then</paragraph>
<paragraph role="code" id="par_id3156333" xml-lang="en-US" l10n="U" oldref="55">Do</paragraph>
<paragraph role="code" id="par_id3153947" xml-lang="en-US" l10n="U" oldref="56">MsgBox sFile</paragraph>
<paragraph role="code" id="par_id3150327" xml-lang="en-US" l10n="U" oldref="57">sFile = Dir$</paragraph>
<paragraph role="code" id="par_id3150749" xml-lang="en-US" l10n="U" oldref="58">Loop Until sFile = ""</paragraph>
<paragraph role="code" id="par_id3153765" xml-lang="en-US" l10n="U" oldref="59">End If</paragraph>
<paragraph role="code" id="par_id3148914" xml-lang="en-US" l10n="U" oldref="60">End Sub</paragraph>
</body>
</helpdocument>