While...End While
A While...End While structure executes a series of statements as long as a given condition is True.
Syntax
While
expression [statements]
End While
Arguments
expression
Any expression that can be evaluated to return a result. The result type of the expression will be coerced to True or False.
statements
One or more statements executed while expression is True.
Remarks
If expression is True, all statements in statements are executed until the End While statement is encountered. Control then returns to the While statement and expression is again checked. If the condition is still True, the process is repeated. If it is not True, execution resumes with the statement following the End While statement.
While...End While loops can be nested to any level. Each End While matches the most recent While.
The
Do...Loop statement provides a more structured and flexible way to perform looping. Any loop construct created with a
While...End While can be created using a
Do...Loop statement.
Example
The following example illustrates using a
While...End While statement to loop through the
VariableInstance objects in an MDM Document, writing their English (United States) question texts to a text file. To run this example using the
mrScript Command Line Runner, use the
/m: option to specify an .
mdd file.
Dim fso, txtfile, Counter
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("variables.txt", True)
Counter = 0
While Counter < MDM.Variables.Count - 1
txtfile.WriteLine(MDM.Variables[Counter].Labels["Label"].Text["Question"]["ENU"])
Counter = Counter + 1
End While
The following example uses a counter so that the first four iterations of the question are asked.
Dim Counter
Counter = 0
While Counter < 4
Rating[Counter].Wine.Ask()
End While
See also