summaryrefslogtreecommitdiffstats
path: root/source/text/sbasic/shared/03090203.xhp
blob: dad29dca34f8ea38e27a9d0cfacf7b4e683a15a4 (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
<?xml version="1.0" encoding="UTF-8"?>

<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   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 .
 -->

<helpdocument version="1.0">
<meta>
<topic id="textsbasicshared03090203xml" indexer="include" status="PUBLISH">
<title xml-lang="en-US" id="tit">While...Wend Statement</title>
<filename>/text/sbasic/shared/03090203.xhp</filename>
</topic>
<history>
<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
</history>
</meta>
<body>

  <section id="whilewend">
  <bookmark xml-lang="en-US" branch="index" id="bm_id3150400">
    <bookmark_value>While;While...Wend loop</bookmark_value>
    <bookmark_value>While;While Wend loop</bookmark_value>
  </bookmark>
  <paragraph id="hd_id3150400" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03090203.xhp" name="While...Wend Statement">While...Wend Statement</link></paragraph>
    <paragraph xml-lang="en-US" role="paragraph" id="par_id3151211">When a program encounters a <literal>While</literal> statement, it tests the condition. If the condition is <literal>False</literal>, the program continues directly following the <literal>Wend</literal> statement. If the condition is <literal>True</literal>, the loop is executed until the program finds <literal>Wend</literal> and then jumps back to the <emph>While</emph> statement. If the condition is still <literal>True</literal>, the loop is executed again.</paragraph>
  </section>
  <paragraph xml-lang="en-US" id="par_id3151041" role="paragraph">Unlike the <link href="text/sbasic/shared/03090201.xhp" name="Do...Loop">Do...Loop</link> statement, you cannot cancel a <emph>While...Wend</emph> loop with <link href="text/sbasic/shared/03090412.xhp" name="Exit">Exit</link>. Never exit a <literal>While...Wend</literal> loop with <link href="text/sbasic/shared/03090302.xhp" name="GoTo">GoTo</link>, since this can cause a run-time error.</paragraph>
  <paragraph role="paragraph" id="par_id3145172" xml-lang="en-US">A <literal>Do...Loop</literal> is more flexible than a <literal>While...Wend.</literal></paragraph>

  <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
  <paragraph role="image" id="par_id831588865616326">
    <image src="media/helpimg/sbasic/While_statement.svg" id="img_id651588865616326"><alt id="alt_id281588865616326">While syntax</alt></image>
  </paragraph>
<bascode>
    <paragraph role="bascode" id="par_id3147288" localize="false">While Condition [statements] Wend</paragraph>
</bascode>
  <embed href="text/sbasic/shared/00000003.xhp#functexample"/>
<bascode>
  <paragraph role="bascode" id="par_id3159153" localize="false">Sub ExampleWhileWend</paragraph>
  <paragraph role="bascode" id="par_id3151114" localize="false">    Dim stext As String</paragraph>
  <paragraph role="bascode" id="par_id3153143" localize="false">    Dim iRun As Integer</paragraph>
  <paragraph role="bascode" id="par_id3155306" xml-lang="en-US">    sText =&quot;This is a short text&quot;</paragraph>
  <paragraph role="bascode" id="par_id3154011" localize="false">    iRun = 1</paragraph>
  <paragraph role="bascode" id="par_id3147215" localize="false">    While iRun &lt; Len(sText)</paragraph>
  <paragraph role="bascode" id="par_id3147427" localize="false">        If Mid(sText,iRun,1 )&lt;&gt; &quot; &quot; Then Mid( sText ,iRun, 1) = Chr( 1 + Asc( Mid(sText,iRun,1 )) )</paragraph>
  <paragraph role="bascode" id="par_id3149665" localize="false">        iRun = iRun + 1</paragraph>
  <paragraph role="bascode" id="par_id3152939" localize="false">    Wend</paragraph>
  <paragraph role="bascode" id="par_id3153189" xml-lang="en-US">    MsgBox sText,0,&quot;Text encoded&quot;</paragraph>
  <paragraph role="bascode" localize="false" id="par_id3145251">End Sub</paragraph>
</bascode>

  <section id="relatedtopics">
    <paragraph role="paragraph" id="par_id161588865796615"><link href="text/sbasic/shared/03090201.xhp" name="Do...Loop statement">Do...Until</link> or <link href="text/sbasic/shared/03090201.xhp" name="Do...While statement">Do...While</link> statement</paragraph>
    <paragraph role="paragraph" id="par_id281588865818334"><link href="text/sbasic/shared/03090412.xhp" name="Exit statement">Exit</link> statement</paragraph>
  </section>

 </body>
</helpdocument>