15 lines
2.0 KiB
HTML
15 lines
2.0 KiB
HTML
<html><head><title>Command: For </title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'><link rel='stylesheet' href='../css/commands.css' type='text/css'></head><body><span class='Command'> For variable </span></p><span class='header'>Definition:</span> <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>First command of the FOR ... NEXT loop.</td></tr></table><span class='header'><br>Parameter Description:</span> <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>variable = any valid variable name</td></tr></table><p class='header'>Command Description: <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>The first command of the FOR ... NEXT loop, this command is used to assign a variable to a range of numbers in sequence and execute a set of code that many times. Using the <a href='STEP.htm'>STEP</a> command allows you to skip a certain value between each loop of the code.<br>
|
|
<br>
|
|
This is frequently used when a specific pattern of numbers is needed to perform an evolution (moving something from point A to point B, adding a value to a score incrementally, etc). This allows you to assign a variable with the current value of the loop. See the example for more.<br>
|
|
Note: Unlike many BASIC languages, the <a href='NEXT.htm'>NEXT</a> command does NOT use the FOR command's variable as an identifier. If you have nested FOR ... NEXT commands, the language will automatically match the NEXT with the nearest FOR command.</td></tr></table><p class='header'>Example: <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>; Print the values 1 through 10<br>
|
|
For t = 1 To 10<br>
|
|
Print t<br>
|
|
Next<br>
|
|
<br>
|
|
; Print the values 1,3,5,7,9<br>
|
|
For t = 1 To 10 Step 2<br>
|
|
Print t<br>
|
|
Next<br>
|
|
</td></tr></table><p><b><a target="_top" href="../index.htm">Index</a></b></p></body>
|
|
</html>
|