Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

FOR…NEXT – PB Docs 2021 – PowerBuilder Library

FOR…NEXT – PB Docs 2021

FOR…NEXT

Description

A control structure that is a numerical iteration, used to execute
one or more statements a specified number of times.

Syntax

Parameter

Description

varname

The name of the iteration counter variable. It can be
any numerical type (byte, integer, double, real, long, longlong,
or decimal), but integers provide the fastest
performance.

start

Starting value of varname.

end

Ending value of varname.

increment (optional)

The increment value. Increment must be a constant and
the same datatype as varname. If you enter an increment, STEP is
required. +1 is the default increment.

statementblock

The block of statements you want to
repeat.

Ending statement

You can end the FOR loop with the keywords END FOR instead of
NEXT.

Usage

Using the start and end parameters

For a positive increment, end must be greater than start. For a
negative increment, end must be less than start.

When increment is positive and start is greater than end,
statementblock does not execute. When increment is negative and start is
less than end, statementblock does not execute.

When start and end are expressions, they are reevaluated on each
pass through the loop. If the expression’s value changes, it affects the
number of loops. Consider this example — the body of the loop changes the
number of rows, which changes the result of the RowCount function:

A variable as the step increment

If you need to use a variable for the step increment, you can use
one of the DO…LOOP constructions and increment the counter yourself
within the loop.

Nesting

You can nest FOR…NEXT statements. You must have a NEXT or END
FOR for each FOR.

Avoid overflow

If start or end is too large for the datatype of varname,
varname will overflow, which might create an infinite loop. Consider
this statement for the integer li_int:

The end value 50000 is too large for an integer. When li_int is
incremented, it overflows to a negative value before reaching 50000,
creating an infinite loop.

Examples

Example 1

These statements add 10 to A as long as n is >=5 and
<=25:

Example 2

These statements add 10 to A and increment n by 5 as long as n is
>= 5 and <=25:

Example 3

These statements contain two lines that will never execute because
increment is negative and start is less than end:

Example 4

These are nested FOR…NEXT statements:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x