21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Branching 28<br />

Source: http:/ / <strong>wiki</strong>. services. openoffice. <strong>org</strong>/ w/ index. php? title=Documentation/ <strong>BASIC</strong>_<br />

<strong>Guide</strong>/ Branching&oldid=108797<br />

Principal Authors: Fpe, Ccornell, Pitonyak<br />

Loops<br />

A loop executes a code block for the number of passes that are specified. You can also have<br />

loops with an undefined number of passes.<br />

For. . . Next<br />

The For...Next loop has a fixed number of passes. The loop counter defines the number of<br />

times that the loop is to be executed. In the following example, variable I is the loop<br />

counter, with an initial value of 1. The counter is incremented by 1 at the end of each pass.<br />

When variable I equals 10, the loop stops.<br />

Dim I<br />

For I = 1 To 10<br />

' ... Inner part of loop<br />

Next I<br />

If you want to increment the loop counter by a value other than 1 at the end of each pass,<br />

use the Step function:<br />

Dim I<br />

For I = 1 To 10 Step 0.5<br />

' ... Inner part of loop<br />

Next I<br />

In the preceding example, the counter is increased by 0.5 at the end of each pass and the<br />

loop is executed 19 times.<br />

You can also use negative step values:<br />

Dim I<br />

For I = 10 To 1 Step -1<br />

' ... Inner part of loop<br />

Next I<br />

In this example, the counter begins at 10 and is reduced by 1 at the end of each pass until<br />

the counter is 1.<br />

The Exit For instruction allows you to exit a For loop prematurely. In the following example,<br />

the loop is terminated during the fifth pass:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!