Domino Code Fragment

Code Name*
Conditional Branching: The FOR Statement
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.141.244.153
Description*
The For statement gives you the ability to execute a block of code a certain number of times.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
For instance, if you prompted a user how many students were in a class, and the user entered `6', you could then ask for six student names. The For statement uses a counter to keep track of how many times the loop has been executed. The counter is a variable, usually of type integer or variant, which is incremented automatically by one when the Next statement is executed.
Syntax
For counter = first To last First represents the first number to increment from, last is the number to increment to.
statements
Next

The following example displays the counter as it is incremented five times.

Click here to view the example.

Dim X As Variant
For X = 1 To 5
MessageBox X
Next

This example asks how many times it should display its message. It then displays the message the number of times you specify. Notice the value for X is the number you entered. This is how the loop executes the correct number of times.

Click here to view the example.

Dim I As Variant 'Declare I as type Variant
Dim X As Variant
'Declare X as type Variant
X = Inputbox("Number of times to see the message?")
'Get number of times to ask
'user for a number
While Not Isnumeric(X)
'While X is not a number
X = Inputbox("Enter a number!")
'Ask for a value that is numeric
Wend
'End of WHILE loop
For I = 1 To X
'For X number of times, execute
'the following code
Messagebox("This is message " + Cstr(I))
'Show the user how many times
'the loop has executed
Next
'End of FOR loop