Defining Object Reference Variables

Working with Iterative Loops

LotusScript offers numerous iterative looping constructs including the DO, FOR, and WHILE statements. Each of these statements continuously loops through one or more executable statements based on an expression, value, or computed result.

There are two variations of the DO statement. This statement be can set up to loop either WHILE an expression is true or UNTIL an expression equates to true. In both cases, the condition can be evaluated at the start or end of the loop. The syntax is as follows:

DO [WHILE | UNTIL] condition


Alternatively, you can check the expression at the end of the loop by utilizing the following syntax:

LOOP [WHILE | UNTIL] condition

For example, the following code initializes a variable called counter to zero. Next, the LotusScript tests the condition to see if counter is less than five. For each loop, counter is incremented and a message is displayed to the user. The loop terminates when counter reaches the value of five.

Dim counter As Integer
counter = 0
Do While counter < 5
 counter = counter + 1
 Messagebox counter

The FOR statement is used to loop a specific number of times through a series of LotusScript statements. With this loop statement, a variable is set and incremented. The loop continues to execute until the desired number of iterations is reached. Optionally, you can specify an incremental value. If the STEP value is omitted, it defaults to an incremental value of one.

For example, an incremental step value of two means the loop will count by twos. The syntax for this statement is as follows:

FOR counter = startnum TO endnum [STEP increment]
NEXT counter

For example, the following displays the counter number to the user. This counter value starts at one and loops five times. When the counter value equals six, the looping stops.

For counter = 1 To 5
 Messagebox counter

Finally, the WHILE statement loops continuously, provided that the specified condition equates to a true value. When the condition returns a false value, LotusScript immediately exits the loop.

WHILE condition

For example, this code asks the user if they would like to continue. If the user specifies either "Y" or "y", then the input box is redisplayed. The looping stops if any other value is returned.

Dim result As String
result = Inputbox$("Do you want to continue (Y / N)?")

While result = "Y" Or result = "y"
 result = Inputbox$("Do you want to continue (Y / N)?")


Best practices in software programming suggest that you should always create iterative loops that exit by default. This will prevent the possibility of an endless loop. An endless loop has the potential to lock up the application and client workstation and possibly to consume a significant amount of memory or CPU on the server. The EXIT statement can be used to conditionally exit an iterative loop. The following shows the syntax for this statement:

EXIT LoopType

where LoopType represents the current iterative loop such as DO, FOR, or FORALL. This statement can also be used to exit from a FUNCTION, SUB, or PROPERTY.

Communicating with Users

An Introduction to the Lotus Domino Tool Suite

Getting Started with Designer

Navigating the Domino Designer Workspace

Domino Design Elements

An Introduction to Formula Language

An Introduction to LotusScript

Fundamentals of a Notes Application

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management


Application Deployment and Maintenance


Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?

show all menu

Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott
Similar book on Amazon © 2008-2017.
If you may any questions please contact us: