Loops adds +1 to #i?

Hello

The SOFiSTiK loop is based on the Fortran DO-loops.

grafik
(source: Fortran - Do Loop Construct)

So the increment is updated after the code block.
In your example, this means that the variable is incremented to 5 after the last loop iteration.

The range() function in python is working in a different way. The last value 5 is only an argument in the range() function. So range(5) greates the vector [0,1,2,3,4].
Now the Python for loop executes the loop for each entry of the vector.

If you want to recreate the same program behaviour in python, you have to use the following code.

i = 0
while i < 5:
  print(i)
  i += 1

print(i)

Further information:

Best regards
Frederik Höller
Your SOFiSTiK Support Team

1 Like