Revision history for KeyPgFornext


Revision [21595]

Last edited on 2016-09-13 14:39:37 by fxm [Added an example of infinite For...Next loop in case of loop up to the highest value of an Ubyte iterator]
Additions:
For ub As UByte = 240 To 255 '' Infinite loop because the end criterion value (255+1=256) can never be reached by the UByte iterator
Deletions:
For ub As UByte = 240 To 255


Revision [21594]

Edited on 2016-09-13 10:27:48 by fxm [Added an example of infinite For...Next loop in case of loop up to the highest value of an Ubyte iterator]
Additions:
Next ub%%The same applies to lowest value of an UByte iterator (0) in case of loop down (negative ##//stepvalue//##).
Deletions:
Next ub%%


Revision [21593]

Edited on 2016-09-13 10:03:42 by fxm [Added an example of infinite For...Next loop in case of loop up to the highest value of an Ubyte iterator]
Additions:
Print ub
If Inkey <> "" Then Exit For
Sleep 10
Deletions:
Print ub
If Inkey <> "" Then Exit For
Sleep 10


Revision [21592]

Edited on 2016-09-13 09:57:27 by fxm [Added an example of infinite For...Next loop in case of loop up to the highest value of an Ubyte iterator]
Additions:
Example of infinite For...Next loop in case of loop up to the highest value of an Ubyte iterator (255):
{{fbdoc item="filename" value="examples/manual/control/for-next3.bas"}}%%(freebasic)
For ub As UByte = 240 To 255
Print ub
If Inkey <> "" Then Exit For
Sleep 10
Next ub%%


Revision [20930]

Edited on 2016-03-13 01:06:36 by fxm [Formatting]

No Differences

Revision [20247]

Edited on 2016-02-10 16:00:41 by DkLwikki [Update link format]
Additions:
**For** //iterator// [ [[KeyPgAs|as]] [[DataType|datatype]] ] = //startvalue// **To** //endvalue// [ **Step** //stepvalue// ]
Note: In some dialects, the temporary variables holding ##//stepvalue//## and ##//endvalue//## go out of scope at the end of the loop, and their values are not guaranteed to remain unchanged once any code following the loop has been executed. For this reason, it is recommended never to branch out of a ##**For...Next**## loop (using ##[[KeyPgGoto|Goto]]## or similar), and then jump back into the middle of it later when in the //[[CompilerOptlang|-lang fb]]// or //[[CompilerOptlang|-lang deprecated]]// dialect.
The iterator must be an intrinsic scalar: only ##[[KeyPgStatic|Static]]##/##[[KeyPgShared|Shared]]## variables and local variables can be used; no other kind can be used, including array elements, UDT members, ##[[KeyPgByref|Byref]]## parameters or any kind of dereferenced address.
The ##//iterator//## may be defined having the same scope as the ##**For**## statement by using the ##[[KeyPgAs|as]] [[DataType|datatype]]## syntax. With this syntax, ##//iterator//## is created and destroyed within the ##**For...Next**## scope. See dialect differences below.
If an ##[[KeyPgExit|Exit]]## ##**For**## statement is encountered inside the ##//statement block//##, the loop is terminated, and execution resumes immediately following the enclosing ##**Next**## statement. If a ##[[KeyPgContinue|Continue]]## ##**For**## statement is encountered, the rest of the ##//statement block//## is skipped until the block's corresponding ##**Next**## statement. The counter's value is incremented and the loop restarted if it is still within the bounds given by ##//endvalue//##.
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte|UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See ##[[TblVarTypes|Standard Data Type Limits]]## to find the upper and lower limits for the standard data types.
##//For//##, ##//Next//##, and ##//Step//## are operators that can be overloaded inside user defined types. See ##[[KeyPgOpFor|Operator For]]##, ##[[KeyPgOpNext|Operator Next]]##, ##[[KeyPgOpStep|Operator Step]]##
- In the //[[CompilerOptlang|-lang fb]]// and //[[CompilerOptlang|-lang deprecated]]// dialects, variables declared inside a ##**For**##..##**Next**## block are visible only inside the block, and cannot be accessed outside it.
- In the //[[CompilerOptlang|-lang qb]]// and //[[CompilerOptlang|-lang fblite]]// dialects, variables declared inside a ##**For**##..##**Next**## block (including the counter if declared, and any temporary variables used to hold ##//endvalue//## or //##stepvalue//##), have a procedure-wide [[ProPgVariableScope|scope]] as in QB
- ##[[KeyPgByref|Byref]]## arguments cannot be used as counters.
- ##[[KeyPgContinue|Continue]]##
- ##[[KeyPgDoloop|Do...Loop]]##
- ##[[KeyPgExit|Exit]]##
Deletions:
**For** //iterator// [ [[KeyPgAs as]] [[DataType datatype]] ] = //startvalue// **To** //endvalue// [ **Step** //stepvalue// ]
Note: In some dialects, the temporary variables holding ##//stepvalue//## and ##//endvalue//## go out of scope at the end of the loop, and their values are not guaranteed to remain unchanged once any code following the loop has been executed. For this reason, it is recommended never to branch out of a ##**For...Next**## loop (using ##[[KeyPgGoto Goto]]## or similar), and then jump back into the middle of it later when in the //[[CompilerOptlang -lang fb]]// or //[[CompilerOptlang -lang deprecated]]// dialect.
The iterator must be an intrinsic scalar: only ##[[KeyPgStatic Static]]##/##[[KeyPgShared Shared]]## variables and local variables can be used; no other kind can be used, including array elements, UDT members, ##[[KeyPgByref Byref]]## parameters or any kind of dereferenced address.
The ##//iterator//## may be defined having the same scope as the ##**For**## statement by using the ##[[KeyPgAs as]] [[DataType datatype]]## syntax. With this syntax, ##//iterator//## is created and destroyed within the ##**For...Next**## scope. See dialect differences below.
If an ##[[KeyPgExit Exit]]## ##**For**## statement is encountered inside the ##//statement block//##, the loop is terminated, and execution resumes immediately following the enclosing ##**Next**## statement. If a ##[[KeyPgContinue Continue]]## ##**For**## statement is encountered, the rest of the ##//statement block//## is skipped until the block's corresponding ##**Next**## statement. The counter's value is incremented and the loop restarted if it is still within the bounds given by ##//endvalue//##.
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See ##[[TblVarTypes Standard Data Type Limits]]## to find the upper and lower limits for the standard data types.
##//For//##, ##//Next//##, and ##//Step//## are operators that can be overloaded inside user defined types. See ##[[KeyPgOpFor Operator For]]##, ##[[KeyPgOpNext Operator Next]]##, ##[[KeyPgOpStep Operator Step]]##
- In the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang deprecated]]// dialects, variables declared inside a ##**For**##..##**Next**## block are visible only inside the block, and cannot be accessed outside it.
- In the //[[CompilerOptlang -lang qb]]// and //[[CompilerOptlang -lang fblite]]// dialects, variables declared inside a ##**For**##..##**Next**## block (including the counter if declared, and any temporary variables used to hold ##//endvalue//## or //##stepvalue//##), have a procedure-wide [[ProPgVariableScope scope]] as in QB
- ##[[KeyPgByref Byref]]## arguments cannot be used as counters.
- ##[[KeyPgContinue Continue]]##
- ##[[KeyPgDoloop Do...Loop]]##
- ##[[KeyPgExit Exit]]##


Revision [16902]

Edited on 2013-07-31 09:57:26 by FxMwikki [Corrected bad formatting of link to TblVarTypes (I hope that will repair the link broken for .chm)]
Additions:
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See ##[[TblVarTypes Standard Data Type Limits]]## to find the upper and lower limits for the standard data types.
Deletions:
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See [[TblVarTypes Standard Data Type Limits]] to find the upper and lower limits for the standard data types.


Revision [16898]

Edited on 2013-07-31 09:43:55 by FxMwikki [Corrected bad formatting of link to TblVarTypes (I hope that will repair the link broken for the doc]
Additions:
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See [[TblVarTypes Standard Data Type Limits]] to find the upper and lower limits for the standard data types.
Deletions:
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See [[TblVarTypes]] to find the upper and lower limits for the standard data types.


Revision [16737]

Edited on 2013-04-29 08:18:07 by TheAdventMaster [Corrected bad formatting of link to TblVarTypes (I hope that will repair the link broken for the doc]
Additions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. Comparison operators such as < and > will not be effective as ##//stepvalue//## or ##//endvalue//## because the expressions will not be re-evaluated while the loop is running. (The results of the expressions used to define them may be changed, but these changes will not affect the execution of the ##**For**## loop.) See examples.
Deletions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. (The results of the expressions used to define them may be changed, but these changes will not affect the execution of the ##**For**## loop.) See examples.


Revision [16729]

Edited on 2013-04-28 17:34:59 by CountingPine [Warning about jumping into FOR loops in fb/deprecated]
Additions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. (The results of the expressions used to define them may be changed, but these changes will not affect the execution of the ##**For**## loop.) See examples.
Note: In some dialects, the temporary variables holding ##//stepvalue//## and ##//endvalue//## go out of scope at the end of the loop, and their values are not guaranteed to remain unchanged once any code following the loop has been executed. For this reason, it is recommended never to branch out of a ##**For...Next**## loop (using ##[[KeyPgGoto Goto]]## or similar), and then jump back into the middle of it later when in the //[[CompilerOptlang -lang fb]]// or //[[CompilerOptlang -lang deprecated]]// dialect.
- In the //[[CompilerOptlang -lang qb]]// and //[[CompilerOptlang -lang fblite]]// dialects, variables declared inside a ##**For**##..##**Next**## block (including the counter if declared, and any temporary variables used to hold ##//endvalue//## or //##stepvalue//##), have a procedure-wide [[ProPgVariableScope scope]] as in QB
Deletions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. (the variables that define them can be changed, but changing those variables inside the ##**For**## loop will not affect its execution. See examples)
- In the //[[CompilerOptlang -lang qb]]// and //[[CompilerOptlang -lang fblite]]// dialects, variables declared inside a ##**For**##..##**Next**## block have a procedure-wide [[ProPgVariableScope scope]] as in QB


Revision [15884]

Edited on 2012-01-29 18:07:30 by CountingPine [Formatting; warning about the endvalue being at the bounds of a datatype range]
Additions:
A ##**For...Next**## loop initializes ##//iterator//## to ##//startvalue//##, then executes the ##//statement block//##, incrementing ##//iterator//## by ##//stepvalue//## until it exceeds ##//endvalue//##. If ##//stepvalue//## is not explicitly given it will set to ##1##.
**Note**: for integer data types, it is not possible to loop up to the highest possible value (or down to the lowest possible value) that can be stored in the variable type, because the loop only breaks when the incremented variable exceeds ##//endvalue//##, which can never happen. For example, if you try to iterate an variable from ##0## to ##255##, the loop will only break once the variable reaches ##256## or more. Using a ##[[KeyPgUbyte UByte]]## variable for the counter wouldn't work, because although it can hold the numbers ##0## to ##255##, it cannot hold ##256##. See [[TblVarTypes]] to find the upper and lower limits for the standard data types.
##//For//##, ##//Next//##, and ##//Step//## are operators that can be overloaded inside user defined types. See ##[[KeyPgOpFor Operator For]]##, ##[[KeyPgOpNext Operator Next]]##, ##[[KeyPgOpStep Operator Step]]##
Deletions:
A ##**For...Next**## loop initializes ##//iterator//## to ##//startvalue//##, then executes the ##//statement block//##'s, incrementing ##//iterator//## by ##//stepvalue//## until it reaches ##//endvalue//##. If ##//stepvalue//## is not explicitly given it will set to 1.
##//For//##, ##//Next//##, and ##//Step//## are operators that can be overloaded inside user defined types. See [[KeyPgOpFor Operator For]], [[KeyPgOpNext Operator Next]], [[KeyPgOpStep Operator Step]]


Revision [15582]

Edited on 2011-12-27 15:12:09 by CountingPine [Revert sentence to old edit]
Additions:
- ##[[KeyPgByref Byref]]## arguments cannot be used as counters.
Deletions:
- ##[[KeyPgByref Byref]]## arguments, cannot be used.


Revision [15581]

Edited on 2011-12-27 15:08:52 by CountingPine [Minor changes, remove redundant sentence]
Additions:
If specified, the variable ##//iterator//## will automatically be declared with the type ##//datatype//##
The iterator must be an intrinsic scalar: only ##[[KeyPgStatic Static]]##/##[[KeyPgShared Shared]]## variables and local variables can be used; no other kind can be used, including array elements, UDT members, ##[[KeyPgByref Byref]]## parameters or any kind of dereferenced address.
If an ##[[KeyPgExit Exit]]## ##**For**## statement is encountered inside the ##//statement block//##, the loop is terminated, and execution resumes immediately following the enclosing ##**Next**## statement. If a ##[[KeyPgContinue Continue]]## ##**For**## statement is encountered, the rest of the ##//statement block//## is skipped until the block's corresponding ##**Next**## statement. The counter's value is incremented and the loop restarted if it is still within the bounds given by ##//endvalue//##.
- In the //[[CompilerOptlang -lang qb]]// and //[[CompilerOptlang -lang fblite]]// dialects, variables declared inside a ##**For**##..##**Next**## block have a procedure-wide [[ProPgVariableScope scope]] as in QB
Deletions:
If specified, the variable ##//iterator//## will automatically be declared with the type ##//datatype//##.
The iterator must be an intrinsic scalar: only ##[[KeyPgStatic Static]]##/##[[KeyPgShared Shared]]## variables and procedure-local variables can be used; no other kind can be used, including array elements, UDT members, ##[[KeyPgByref Byref]]## parameters or any kind of dereferenced address.
If an ##[[KeyPgExit Exit]]## ##**For**## statement is encountered inside the ##//statement block//##, the loop is terminated, and execution resumes immediately following the enclosing ##**Next**## statement. If a ##[[KeyPgContinue Continue]]## ##**For**## statement is encountered, the rest of the ##//statement block//## is skipped until the block's corresponding ##**Next**## statement. The counter's value is incremented and the loop restarted if it is still within bounds.
**note**: When a negative ##//stepvalue//## is specified, the ##**For**## statement loops until ##//iterator//## compares **less than** ##//end_value//##.
- In the //[[CompilerOptlang -lang qb]]// and //[[CompilerOptlang -lang fblite]]// dialects, variables declared inside a FOR..NEXT loop have a function-wide [[ProPgVariableScope scope]] as in QB


Revision [15580]

Edited on 2011-12-27 15:04:30 by CountingPine [Some rewording, add [[]] links and mention Byref]
Additions:
The iterator must be an intrinsic scalar: only ##[[KeyPgStatic Static]]##/##[[KeyPgShared Shared]]## variables and procedure-local variables can be used; no other kind can be used, including array elements, UDT members, ##[[KeyPgByref Byref]]## parameters or any kind of dereferenced address.
Deletions:
The iterator must be an intrinsic scalar: only Static/Shared variables and procedure-local variables can be used, neither array element nor UDT element nor any dereferenced address.


Revision [15579]

Edited on 2011-12-27 14:36:17 by FxMwikki [Refine constraints about iterator variable type.]
Additions:
The iterator must be an intrinsic scalar: only Static/Shared variables and procedure-local variables can be used, neither array element nor UDT element nor any dereferenced address.
Deletions:
The iterator must be an intrinsic scalar: it cannot be an array element or an UDT element.


Revision [15578]

Edited on 2011-12-27 13:28:44 by FxMwikki [Refine constraints about iterator variable type.]
Additions:
The iterator must be an intrinsic scalar: it cannot be an array element or an UDT element.
- ##[[KeyPgByref Byref]]## arguments, cannot be used.
Deletions:
- Only variables local to the current procedure/main body can be used as counters. Other kinds of variable, including array elements and ##[[KeyPgByref Byref]]## arguments, cannot be used.


Revision [15577]

Edited on 2011-12-26 15:21:55 by CountingPine [FOR requires local variables; info on CONTINUE FOR; minor changes]
Additions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. (the variables that define them can be changed, but changing those variables inside the ##**For**## loop will not affect its execution. See examples)
The ##//iterator//## may be defined having the same scope as the ##**For**## statement by using the ##[[KeyPgAs as]] [[DataType datatype]]## syntax. With this syntax, ##//iterator//## is created and destroyed within the ##**For...Next**## scope. See dialect differences below.
If an ##[[KeyPgExit Exit]]## ##**For**## statement is encountered inside the ##//statement block//##, the loop is terminated, and execution resumes immediately following the enclosing ##**Next**## statement. If a ##[[KeyPgContinue Continue]]## ##**For**## statement is encountered, the rest of the ##//statement block//## is skipped until the block's corresponding ##**Next**## statement. The counter's value is incremented and the loop restarted if it is still within bounds.
**note**: When a negative ##//stepvalue//## is specified, the ##**For**## statement loops until ##//iterator//## compares **less than** ##//end_value//##.
for i as single = 3 to 0 step -0.5
- In the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang deprecated]]// dialects, variables declared inside a ##**For**##..##**Next**## block are visible only inside the block, and cannot be accessed outside it.
- Only variables local to the current procedure/main body can be used as counters. Other kinds of variable, including array elements and ##[[KeyPgByref Byref]]## arguments, cannot be used.
Deletions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. (the variables that define them can be changed, but changing those variables inside the ##**for**## loop will not affect its execution. See examples)
The ##//iterator//## may be defined having the same scope as the ##**For**## statement by using the ##[[KeyPgAs as]] [[DataType datatype]]## syntax. With this syntax, //iterator// is created and destroyed within the ##**For...Next**## scope. See dialect differences below.
If an ##[[KeyPgExit Exit]]## ##**For**## statement is encountered inside the ##//statement block//##, the loop is terminated, and execution resumes immediately following the enclosing ##**Next**## statement. If a ##[[KeyPgContinue Continue]]## ##**For**## statement is encountered, the rest of the ##//statement block//## is skipped and execution resumes at the FOR statement.
**note**: When a negative ##//stepvalue//## is specified, the ##**For**## statement loops until ##//iterator//## compares //less than// ##//end_value//##.
Dim i As Single
dim i as single
for i = 3 to 0 step -0.5
- In the //[[CompilerOptlang -lang fb]]// and //[[CompilerOptlang -lang deprecated]]// dialects, variables declared inside a ##**For**##..##**Next**## block are visible only inside the block, and can't be accessed outside it.
- ##[[KeyPgByref Byref]]## arguments cannot be used as counters.


Revision [14590]

Edited on 2010-05-25 22:21:48 by CountingPine [Separate examples, clarify new example, minor text clarifications, formatting]
Additions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the ##**For**## statement and thus neither can be changed inside the ##**For**## loop. (the variables that define them can be changed, but changing those variables inside the ##**for**## loop will not affect its execution. See examples)
The ##//iterator//## may be defined having the same scope as the ##**For**## statement by using the ##[[KeyPgAs as]] [[DataType datatype]]## syntax. With this syntax, //iterator// is created and destroyed within the ##**For...Next**## scope. See dialect differences below.
The ##**For**## statement causes the execution of the statements in the ##//statement block//## until ##//iterator//## compares **greater than** ##//endvalue//## (or **less than** ##//endvalue//## if ##//stepvalue// < 0##). ##//iterator//## will be incremented the amount of ##//stepvalue//## following each execution of the ##//statement block//##. If an increment is not given, ##//iterator//## will be implicitly incremented by ##1##.
##//For//##, ##//Next//##, and ##//Step//## are operators that can be overloaded inside user defined types. See [[KeyPgOpFor Operator For]], [[KeyPgOpNext Operator Next]], [[KeyPgOpStep Operator Step]]
next i%%
{{fbdoc item="filename" value="examples/manual/control/for-next2.bas"}}%%(freebasic)
dim as integer i, j, k, toTemp, stepTemp
j = 0: k = 0 '' Changing j and k has no effect on the current loop.
print i;
print
i = 0: toTemp = j: stepTemp = k
do while iif(stepTemp >= 0, i <= toTemp, i >= toTemp)
j = 0: k = 0 '' Changing j and k has no effect on the current loop.
print i;
i += stepTemp
loop
print%%
Deletions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the for statement and thus neither can be changed inside the for loop. (the variables that define them can be changed, but changing those variables inside the for loop will not affect its execution. See examples)
The //iterator// may be defined having the same scope as the ##**For**## statement by using the ##[[KeyPgAs as]] [[DataType datatype]]## syntax. With this syntax, //iterator// is created and destroyed within the ##**For...Next**## scope. See dialect differences below.
The ##**For**## statement causes the execution of the statements in the ##//statement block//## until ##//iterator//## compares **greater than** ##//endvalue//##. ##//iterator//## will be incremented the amount of ##//stepvalue//## following each execution of the ##//statement block//##. If an increment is not given, ##//iterator//## will be implicitly incremented by 1.
//For//, //Next//, and //Step// are operators that can be overloaded inside user defined types. See [[KeyPgOpFor Operator For]], [[KeyPgOpNext Operator Next]], [[KeyPgOpStep Operator Step]]
dim as integer j, k, jTemp, kTemp
j = 0
k = 0
print "i is " & i ' Changing j and k has no effect on the current loop.
jTemp = j: kTemp = k
for i = 0 To jTemp step kTemp
j = 0
k = 0
print "i is " & i ' Changing j and k has no effect on the current loop.
%%


Revision [14588]

Edited on 2010-05-18 13:36:34 by AgAmemnus [added some examples]
Additions:
dim i as single
for i = 3 to 0 step -0.5
print "i is " & i
next i
dim as integer j, k, jTemp, kTemp
j = 9: k = 1
for i = 0 to j step k
j = 0
k = 0
print "i is " & i ' Changing j and k has no effect on the current loop.
next i
' Internally, this is what the above example does:
j = 9: k = 1
jTemp = j: kTemp = k
for i = 0 To jTemp step kTemp
j = 0
k = 0
print "i is " & i ' Changing j and k has no effect on the current loop.
next i
Deletions:
For i = 3 To 0 Step -0.5
Print "i is " & i
Next i


Revision [14587]

Edited on 2010-05-18 13:28:43 by AgAmemnus [increment -> stepvalue, added that endvalue is also stored internally, clarified stepvalue/endvalue ]
Additions:
The values of ##//stepvalue//## and ##//endvalue//## are stored internally immediately following execution of the for statement and thus neither can be changed inside the for loop. (the variables that define them can be changed, but changing those variables inside the for loop will not affect its execution. See examples)

**note**: When a negative ##//stepvalue//## is specified, the ##**For**## statement loops until ##//iterator//## compares //less than// ##//end_value//##.
Deletions:
After initial evaluation, the ##//increment//## is stored internally, and thus cannot be changed for subsequent executions.
**note**: When a negative ##//increment//## is specified, the ##**For**## statement loops until ##//iterator//## compares //less than// ##//end_value//##.


Revision [12830]

The oldest known version of this page was created on 2008-04-01 15:47:31 by JeffMarshall [increment -> stepvalue, added that endvalue is also stored internally, clarified stepvalue/endvalue ]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode