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:

# Using 'step' keyword in 'for' loop to specify the increment value
for var i = 0 to 10 step 2 then
    show(i)
end

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 of i) is executed.

Decrementing:

# Using negative value with 'step' keyword to decrement in 'for' loop
for var i = 10 to 1 step -2 then
    show(i)
end

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 of i) is executed.

Floating-Point Step:

# Using floating-point value with 'step' keyword in 'for' loop
for var i = 0 to 1 step 0.1 then
    show(i)
end

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:

# Nested 'for' loops with 'step' keyword
for var i = 1 to 5 step 2 then
    for var j = 1 to 3 step 1 then
        show("({i}, {j})")
    end
end

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 of i, the inner loop iterates over the values of j 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