step
X3 programming language, the "step" keyword is used within a "for" loop to specify the increment or decrement value for each iteration of the loop variable. Here's how you would use the "step" keyword in conjunction with the "for" loop:
Basic Usage:
Explanation:
In this example, the "for" loop iterates over the values from 0 to 10 (inclusive) with a step size of 2.
The loop variable
i
increments by 2 in each iteration, and the code inside the loop (printing the value ofi
) is executed.
Decrementing:
Explanation:
Here, the loop iterates backwards from 10 to 1 with a step size of -2.
The loop variable
i
decrements by 2 in each iteration, and the code inside the loop (printing the value ofi
) is executed.
Floating-Point Step:
Explanation:
This example demonstrates using a floating-point value (0.1) with the "step" keyword.
The loop variable
i
increments by 0.1 in each iteration, allowing for finer-grained control over the loop.
Nested Loops:
Explanation:
In this example, a nested "for" loop is used with the "step" keyword.
The outer loop iterates over the values of
i
with a step size of 2, and for each iteration ofi
, the inner loop iterates over the values ofj
with a step size of 1.
By incorporating the "step" keyword in your X3 language's "for" loop syntax, you provide users with the flexibility to control the increment or decrement value for each iteration of the loop variable, allowing for more precise looping behavior.
Last updated