For...Next Statement

Relevant for: GUI actions, scripted GUI components, and function libraries

A For...Next loop instructs UFT One to perform one or more statements a specified number of times. It has the following syntax:

For counter = start to end [Step step]
	statement
Next

Item

Description

counter

The variable used as a counter for the number of iterations.

start

The start number of the counter.

end

The last number of the counter.

step

The number to increment at the end of each loop.
Default = 1.
Optional.

statement

A statement, or series of statements, to be performed during the loop.

Example: In the following example, UFT One calculates the factorial value of the price of a speaker using the For statement:

Price = Browser("Advantage Shopping").Page("Advantage Shopping").WebElement("$44.99").GetTOProperty("innertext")
total = 1
For i=1 to Price
    total = total * i
Next
Msgbox "!"& Price & "="& total

Tip: Use the Edit > Code Snippet > For...Next menu command to automatically insert a If...Then statement into your test.