STEP: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The '''STEP''' keyword is used in FOR...NEXT loops to skip through the count or to count down instead of up. Used in graphics to designate a relative coordinate position of a graphics object function. {{PageSyntax}} :: FOR counter_variable = start_point TO stop_point ['''STEP ''interval'''''] :: CIRCLE '''STEP(0, 0)''', 10, 12 * The FOR counter variable is used to designate and pass the current FOR incremented value. * FOR loops without the optional STEP value...")
 
No edit summary
Line 8: Line 8:




* The FOR counter variable is used to designate and pass the current FOR incremented value.  
* The FOR counter variable is used to designate and pass the current FOR incremented value.
* FOR loops without the optional STEP value increment by + 1 every loop.
* FOR loops without the optional STEP value increment by + 1 every loop.
* The STEP increment value can be any literal or variable numerical type. It cannot be changed inside of the loop!
* The STEP increment value can be any literal or variable numerical type. It cannot be changed inside of the loop!
Line 19: Line 19:


''Example:'' Stepping down 2 in a FOR counter loop.
''Example:'' Stepping down 2 in a FOR counter loop.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|FOR...NEXT}} i = 10 {{Cl|TO}} 0 {{Cl|STEP}} -2
{{Cl|FOR...NEXT}} i = 10 {{Cl|TO}} 0 {{Cl|STEP}} -2
   {{Cl|PRINT}} i;
   {{Cl|PRINT}} i;
{{Cl|NEXT}} '' ''
{{Cl|NEXT}}
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}  
{{OutputStart}}
10 8 6 4 2 0  
10 8 6 4 2 0
{{OutputEnd}}
{{OutputEnd}}
:''Note:'' The value of i = -2 after the loop is done.
:''Note:'' The value of i = -2 after the loop is done.
Line 31: Line 31:




::''Graphics Syntax:'' LINE STEP(column1%, row1%)-(column2%, row2%), color_attribute%  
::''Graphics Syntax:'' LINE STEP(column1%, row1%)-(column2%, row2%), color_attribute%




Line 40: Line 40:


''Graphics Example:'' Using STEP coordinates to PAINT a circle's interior.
''Graphics Example:'' Using STEP coordinates to PAINT a circle's interior.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN}} 12
{{Cl|SCREEN}} 12
{{Cl|CIRCLE}} (100, 100), 50, 12
{{Cl|CIRCLE}} (100, 100), 50, 12
{{Cl|PAINT}} {{Cl|STEP}}(0, 0), 13, 12 '' ''
{{Cl|PAINT}} {{Cl|STEP}}(0, 0), 13, 12
{{CodeEnd}}
{{CodeEnd}}
:''Explanation:'' PAINT uses the CIRCLE's center coordinate position to paint the interior.
:''Explanation:'' PAINT uses the CIRCLE's center coordinate position to paint the interior.




''See also:''  
''See also:''
* [[FOR...NEXT]]
* [[FOR...NEXT]]
* [[DRAW]] (see the M relative move function)
* [[DRAW]] (see the M relative move function)

Revision as of 02:46, 23 January 2023

The STEP keyword is used in FOR...NEXT loops to skip through the count or to count down instead of up. Used in graphics to designate a relative coordinate position of a graphics object function.


Syntax

FOR counter_variable = start_point TO stop_point [STEP interval]
CIRCLE STEP(0, 0), 10, 12


  • The FOR counter variable is used to designate and pass the current FOR incremented value.
  • FOR loops without the optional STEP value increment by + 1 every loop.
  • The STEP increment value can be any literal or variable numerical type. It cannot be changed inside of the loop!
  • Start and stop point values can be any literal or variable type and they cannot be changed inside of the loop.
  • STEP interval designates the portion to add or subtract from the FOR variable value.
  • When the STEP interval is positive, the start value should be less than the stop value ot the loop will be ignored.
  • When the STEP interval is negative, the start value should be greater than the stop value or the loop will be ignored.
  • In graphics statements, STEP can be used before a pair of coordinate brackets to indicate that the coordinates are relative to the last graphics statement position. IE the position will be that number of pixels away from the last graphical object.


Example: Stepping down 2 in a FOR counter loop.

FOR...NEXT i = 10 TO 0 STEP -2
  PRINT i;
NEXT
10 8 6 4 2 0
Note: The value of i = -2 after the loop is done.


Graphics Syntax: LINE STEP(column1%, row1%)-(column2%, row2%), color_attribute%


  • STEP coordinate positions are relative positive or negative pixel moves from the previous graphics object's last coordinate. After a CIRCLE statement, the relative coordinates would be from its center.
  • STEP can be used before the LINE, CIRCLE, PSET, PRESET, PAINT or DRAW graphics object coordinates.


Graphics Example: Using STEP coordinates to PAINT a circle's interior.

SCREEN 12
CIRCLE (100, 100), 50, 12
PAINT STEP(0, 0), 13, 12
Explanation: PAINT uses the CIRCLE's center coordinate position to paint the interior.


See also:



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage