diff options
Diffstat (limited to 'source/text/sbasic/shared/03090202.xhp')
-rw-r--r-- | source/text/sbasic/shared/03090202.xhp | 155 |
1 files changed, 78 insertions, 77 deletions
diff --git a/source/text/sbasic/shared/03090202.xhp b/source/text/sbasic/shared/03090202.xhp index fb9945697a..4ac247a567 100644 --- a/source/text/sbasic/shared/03090202.xhp +++ b/source/text/sbasic/shared/03090202.xhp @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> - - +<helpdocument version="1.0"> <!-- * This file is part of the LibreOffice project. * @@ -17,88 +16,90 @@ * 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="textsbasicshared03090202xml" indexer="include" status="PUBLISH"> -<title id="tit" xml-lang="en-US">For...Next Statement [Runtime]</title> -<filename>/text/sbasic/shared/03090202.xhp</filename> -</topic> -<history> -<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created> -</history> + <topic id="textsbasicshared03090202xml" indexer="include" status="PUBLISH"> + <title id="tit" xml-lang="en-US">For...Next Statement [Runtime]</title> + <filename>/text/sbasic/shared/03090202.xhp</filename> + </topic> </meta> + <body> + + <section id="fornext"> -<bookmark xml-lang="en-US" branch="index" id="bm_id3149205"><bookmark_value>For statement</bookmark_value> -<bookmark_value>To statement</bookmark_value> -<bookmark_value>Step statement</bookmark_value> -<bookmark_value>Next statement</bookmark_value> +<bookmark xml-lang="en-US" branch="index" id="bm_id3149205"> + <bookmark_value>For statement</bookmark_value> + <bookmark_value>To statement</bookmark_value> + <bookmark_value>Step statement</bookmark_value> + <bookmark_value>Next statement</bookmark_value> </bookmark> -<paragraph role="heading" id="hd_id3149205" xml-lang="en-US" level="1" l10n="U" oldref="1"><link href="text/sbasic/shared/03090202.xhp" name="For...Next Statement [Runtime]">For...Next Statement [Runtime]</link></paragraph> -<paragraph role="paragraph" id="par_id3143267" xml-lang="en-US" l10n="U" oldref="2">Repeats the statements between the For...Next block a specified number of times.</paragraph> + + +<paragraph id="hd_id3149205" role="heading" level="1" xml-lang="en-US"><link href="text/sbasic/shared/03090202.xhp" name="For...Next Statement [Runtime]">For...Next Statement [Runtime]</link></paragraph> +<paragraph id="par_id3143267" role="paragraph" xml-lang="en-US">Repeats the statements between the For...Next block a specified number of times.</paragraph> </section> -<paragraph role="heading" id="hd_id3156153" xml-lang="en-US" level="2" l10n="U" oldref="3">Syntax:</paragraph> -<bascode>
-<paragraph role="bascode" id="par_id3148473" xml-lang="en-US" oldref="4">For counter=start To end [Step step]</paragraph>
-<paragraph role="bascode" id="par_id3156024" xml-lang="en-US" oldref="5">statement block</paragraph>
-<paragraph role="bascode" id="par_id3146796" xml-lang="en-US" l10n="U" oldref="6">[Exit For]</paragraph> -<paragraph role="bascode" id="par_id3159414" xml-lang="en-US" l10n="U" oldref="7">statement block</paragraph> -<paragraph role="bascode" id="par_id3153897" xml-lang="en-US" l10n="U" oldref="8">Next [counter]</paragraph> + +<paragraph id="hd_id3156153" role="heading" level="2" xml-lang="en-US">Syntax:</paragraph> +<bascode> +<paragraph id="par_id3148473" role="bascode" xml-lang="en-US">For counter=start To end [Step step]</paragraph> +<paragraph id="par_id3156024" role="bascode" xml-lang="en-US">statement block</paragraph> +<paragraph id="par_id3146796" role="bascode" xml-lang="en-US">[Exit For]</paragraph> +<paragraph id="par_id3159414" role="bascode" xml-lang="en-US">statement block</paragraph> +<paragraph id="par_id3153897" role="bascode" xml-lang="en-US">Next [counter]</paragraph> </bascode> -<paragraph role="heading" id="hd_id3150400" xml-lang="en-US" level="2" l10n="U" oldref="9">Variables:</paragraph> -<paragraph role="paragraph" id="par_id3150358" xml-lang="en-US" l10n="U" oldref="10"> -<emph>Counter:</emph> Loop counter initially assigned the value to the right of the equal sign (start). Only numeric variables are valid. The loop counter increases or decreases according to the variable Step until End is passed.</paragraph> -<paragraph role="paragraph" id="par_id3152455" xml-lang="en-US" l10n="U" oldref="11"> -<emph>Start:</emph> Numeric variable that defines the initial value at the beginning of the loop.</paragraph> -<paragraph role="paragraph" id="par_id3151043" xml-lang="en-US" l10n="U" oldref="12"> -<emph>End:</emph> Numeric variable that defines the final value at the end of the loop.</paragraph> -<paragraph role="paragraph" id="par_id3156281" xml-lang="en-US" l10n="U" oldref="13"> -<emph>Step:</emph> Sets the value by which to increase or decrease the loop counter. If Step is not specified, the loop counter is incremented by 1. In this case, End must be greater than Start. If you want to decrease Counter, End must be less than Start, and Step must be assigned a negative value.</paragraph> -<paragraph role="paragraph" id="par_id3154684" xml-lang="en-US" l10n="U" oldref="14">The <emph>For...Next</emph> loop repeats all of the statements in the loop for the number of times that is specified by the parameters.</paragraph> -<paragraph role="paragraph" id="par_id3147287" xml-lang="en-US" l10n="U" oldref="15">As the counter variable is decreased, $[officename] Basic checks if the end value has been reached. As soon as the counter passes the end value, the loop automatically ends.</paragraph> -<paragraph role="paragraph" id="par_id3159154" xml-lang="en-US" l10n="U" oldref="16">It is possible to nest <emph>For...Next</emph> statements. If you do not specify a variable following the <emph>Next</emph> statement, <emph>Next</emph> automatically refers to the most recent <emph>For</emph> statement.</paragraph> -<paragraph role="paragraph" id="par_id3155306" xml-lang="en-US" l10n="U" oldref="17">If you specify an increment of 0, the statements between <emph>For</emph> and <emph>Next</emph> are repeated continuously.</paragraph> -<paragraph role="paragraph" id="par_id3155854" xml-lang="en-US" l10n="U" oldref="18">When counting down the counter variable, $[officename] Basic checks for overflow or underflow. The loop ends when Counter exceeds End (positive Step value) or is less than End (negative Step value).</paragraph> -<paragraph role="paragraph" id="par_id3145273" xml-lang="en-US" l10n="U" oldref="19">Use the <emph>Exit For</emph> statement to exit the loop unconditionally. This statement must be within a <emph>For...Next</emph> loop. Use the <emph>If...Then</emph> statement to test the exit condition as follows:</paragraph> -<paragraph role="paragraph" id="par_id3153190" xml-lang="en-US" l10n="U" oldref="20">For...</paragraph> -<paragraph role="paragraph" id="par_id3149482" xml-lang="en-US" l10n="U" oldref="21">statements</paragraph> -<paragraph role="paragraph" id="par_id3147124" xml-lang="en-US" l10n="U" oldref="22">If condition = True Then Exit For</paragraph> -<paragraph role="paragraph" id="par_id3153159" xml-lang="en-US" l10n="U" oldref="23">statements</paragraph> -<paragraph role="paragraph" id="par_id3154096" xml-lang="en-US" l10n="U" oldref="24">Next</paragraph> -<paragraph role="paragraph" id="par_id3156286" xml-lang="en-US" l10n="U" oldref="25">Note: In nested <emph>For...Next</emph> loops, if you exit a loop unconditionally with <emph>Exit For</emph>, only one loop is exited.</paragraph> -<paragraph role="heading" id="hd_id3148457" xml-lang="en-US" level="2" l10n="U" oldref="26">Example</paragraph> -<paragraph role="paragraph" id="par_id3151074" xml-lang="en-US" l10n="U" oldref="27">The following example uses two nested loops to sort a string array with 10 elements ( sEntry() ), that are first filled with various contents:</paragraph> + +<paragraph id="hd_id3150400" role="heading" level="2" xml-lang="en-US">Variables:</paragraph> +<paragraph id="par_id3150358" role="paragraph" xml-lang="en-US"> <emph>Counter:</emph> Loop counter initially assigned the value to the right of the equal sign (start). Only numeric variables are valid. The loop counter increases or decreases according to the variable Step until End is passed.</paragraph> +<paragraph id="par_id3152455" role="paragraph" xml-lang="en-US"> <emph>Start:</emph> Numeric variable that defines the initial value at the beginning of the loop.</paragraph> +<paragraph id="par_id3151043" role="paragraph" xml-lang="en-US"> <emph>End:</emph> Numeric variable that defines the final value at the end of the loop.</paragraph> +<paragraph id="par_id3156281" role="paragraph" xml-lang="en-US"> <emph>Step:</emph> Sets the value by which to increase or decrease the loop counter. If Step is not specified, the loop counter is incremented by 1. In this case, End must be greater than Start. If you want to decrease Counter, End must be less than Start, and Step must be assigned a negative value.</paragraph> +<paragraph id="par_id3154684" role="paragraph" xml-lang="en-US">The <emph>For...Next</emph> loop repeats all of the statements in the loop for the number of times that is specified by the parameters.</paragraph> +<paragraph id="par_id3147287" role="paragraph" xml-lang="en-US">As the counter variable is decreased, $[officename] Basic checks if the end value has been reached. As soon as the counter passes the end value, the loop automatically ends.</paragraph> +<paragraph id="par_id3159154" role="paragraph" xml-lang="en-US">It is possible to nest <emph>For...Next</emph> statements. If you do not specify a variable following the <emph>Next</emph> statement, <emph>Next</emph> automatically refers to the most recent <emph>For</emph> statement.</paragraph> +<paragraph id="par_id3155306" role="paragraph" xml-lang="en-US">If you specify an increment of 0, the statements between <emph>For</emph> and <emph>Next</emph> are repeated continuously.</paragraph> +<paragraph id="par_id3155854" role="paragraph" xml-lang="en-US">When counting down the counter variable, $[officename] Basic checks for overflow or underflow. The loop ends when Counter exceeds End (positive Step value) or is less than End (negative Step value).</paragraph> +<paragraph id="par_id3145273" role="paragraph" xml-lang="en-US">Use the <emph>Exit For</emph> statement to exit the loop unconditionally. This statement must be within a <emph>For...Next</emph> loop. Use the <emph>If...Then</emph> statement to test the exit condition as follows:</paragraph> +<paragraph id="par_id3153190" role="paragraph" xml-lang="en-US">For...</paragraph> +<paragraph id="par_id3149482" role="paragraph" xml-lang="en-US">statements</paragraph> +<paragraph id="par_id3147124" role="paragraph" xml-lang="en-US">If condition = True Then Exit For</paragraph> +<paragraph id="par_id3153159" role="paragraph" xml-lang="en-US">statements</paragraph> +<paragraph id="par_id3154096" role="paragraph" xml-lang="en-US">Next</paragraph> +<paragraph id="par_id3156286" role="paragraph" xml-lang="en-US">Note: In nested <emph>For...Next</emph> loops, if you exit a loop unconditionally with <emph>Exit For</emph>, only one loop is exited.</paragraph> + +<paragraph id="hd_id3148457" role="heading" level="2" xml-lang="en-US">Example</paragraph> +<paragraph id="par_id3151074" role="paragraph" xml-lang="en-US">The following example uses two nested loops to sort a string array with 10 elements ( sEntry() ), that are first filled with various contents:</paragraph> <bascode> -<paragraph role="bascode" localize="false" xml-lang="en-US">Sub ExampleSort</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US">Dim sEntry(9) As String</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US">Dim iCount As Integer</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US">Dim iCount2 As Integer</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US">Dim sTemp As String</paragraph> -<paragraph role="bascode" id="par_id3155767" xml-lang="en-US" l10n="U" oldref="42"> sEntry(0) = "Jerry"</paragraph> -<paragraph role="bascode" id="par_id3153711" xml-lang="en-US" l10n="U" oldref="33"> sEntry(1) = "Patty"</paragraph> -<paragraph role="bascode" id="par_id3148993" xml-lang="en-US" l10n="U" oldref="34"> sEntry(2) = "Kurt"</paragraph> -<paragraph role="bascode" id="par_id3156382" xml-lang="en-US" l10n="U" oldref="35"> sEntry(3) = "Thomas"</paragraph> -<paragraph role="bascode" id="par_id3155174" xml-lang="en-US" l10n="U" oldref="36"> sEntry(4) = "Michael"</paragraph> -<paragraph role="bascode" id="par_id3166448" xml-lang="en-US" l10n="U" oldref="37"> sEntry(5) = "David"</paragraph> -<paragraph role="bascode" id="par_id3149255" xml-lang="en-US" l10n="U" oldref="38"> sEntry(6) = "Cathy"</paragraph> -<paragraph role="bascode" id="par_id3149565" xml-lang="en-US" l10n="U" oldref="39"> sEntry(7) = "Susie"</paragraph> -<paragraph role="bascode" id="par_id3145148" xml-lang="en-US" l10n="U" oldref="40"> sEntry(8) = "Edward"</paragraph> -<paragraph role="bascode" id="par_id3145229" xml-lang="en-US" l10n="U" oldref="41"> sEntry(9) = "Christine"</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> For iCount = 0 To 9</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> For iCount2 = iCount + 1 To 9</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> If sEntry(iCount) > sEntry(iCount2) Then</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> sTemp = sEntry(iCount)</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> sEntry(iCount) = sEntry(iCount2)</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> sEntry(iCount2) = sTemp</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> End If</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> Next iCount2</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> Next iCount</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> For iCount = 0 To 9</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> Print sEntry(iCount)</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US"> Next iCount</paragraph> -<paragraph role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph> +<paragraph id="par_idm1341539088" role="bascode" localize="false" xml-lang="en-US">Sub ExampleSort</paragraph> +<paragraph id="par_idm1340517312" role="bascode" localize="false" xml-lang="en-US">Dim sEntry(9) As String</paragraph> +<paragraph id="par_idm1340516080" role="bascode" localize="false" xml-lang="en-US">Dim iCount As Integer</paragraph> +<paragraph id="par_idm1340514848" role="bascode" localize="false" xml-lang="en-US">Dim iCount2 As Integer</paragraph> +<paragraph id="par_idm1340513616" role="bascode" localize="false" xml-lang="en-US">Dim sTemp As String</paragraph> +<paragraph id="par_id3155767" role="bascode" xml-lang="en-US"> sEntry(0) = "Jerry"</paragraph> +<paragraph id="par_id3153711" role="bascode" xml-lang="en-US"> sEntry(1) = "Patty"</paragraph> +<paragraph id="par_id3148993" role="bascode" xml-lang="en-US"> sEntry(2) = "Kurt"</paragraph> +<paragraph id="par_id3156382" role="bascode" xml-lang="en-US"> sEntry(3) = "Thomas"</paragraph> +<paragraph id="par_id3155174" role="bascode" xml-lang="en-US"> sEntry(4) = "Michael"</paragraph> +<paragraph id="par_id3166448" role="bascode" xml-lang="en-US"> sEntry(5) = "David"</paragraph> +<paragraph id="par_id3149255" role="bascode" xml-lang="en-US"> sEntry(6) = "Cathy"</paragraph> +<paragraph id="par_id3149565" role="bascode" xml-lang="en-US"> sEntry(7) = "Susie"</paragraph> +<paragraph id="par_id3145148" role="bascode" xml-lang="en-US"> sEntry(8) = "Edward"</paragraph> +<paragraph id="par_id3145229" role="bascode" xml-lang="en-US"> sEntry(9) = "Christine"</paragraph> +<paragraph id="par_idm1340495152" role="bascode" localize="false" xml-lang="en-US"> For iCount = 0 To 9</paragraph> +<paragraph id="par_idm1340493920" role="bascode" localize="false" xml-lang="en-US"> For iCount2 = iCount + 1 To 9</paragraph> +<paragraph id="par_idm1340492672" role="bascode" localize="false" xml-lang="en-US"> If sEntry(iCount) > sEntry(iCount2) Then</paragraph> +<paragraph id="par_idm1340491296" role="bascode" localize="false" xml-lang="en-US"> sTemp = sEntry(iCount)</paragraph> +<paragraph id="par_idm1340490096" role="bascode" localize="false" xml-lang="en-US"> sEntry(iCount) = sEntry(iCount2)</paragraph> +<paragraph id="par_idm1340488832" role="bascode" localize="false" xml-lang="en-US"> sEntry(iCount2) = sTemp</paragraph> +<paragraph id="par_idm1340487584" role="bascode" localize="false" xml-lang="en-US"> End If</paragraph> +<paragraph id="par_idm1340486352" role="bascode" localize="false" xml-lang="en-US"> Next iCount2</paragraph> +<paragraph id="par_idm1340485120" role="bascode" localize="false" xml-lang="en-US"> Next iCount</paragraph> +<paragraph id="par_idm1340483888" role="bascode" localize="false" xml-lang="en-US"> For iCount = 0 To 9</paragraph> +<paragraph id="par_idm1340482656" role="bascode" localize="false" xml-lang="en-US"> Print sEntry(iCount)</paragraph> +<paragraph id="par_idm1340481408" role="bascode" localize="false" xml-lang="en-US"> Next iCount</paragraph> +<paragraph id="par_idm1340480176" role="bascode" localize="false" xml-lang="en-US">End Sub</paragraph> </bascode> </body> -</helpdocument> + +</helpdocument>
\ No newline at end of file |