godot while loop 1

godot while loop

var fuel = 1000
var speed = 0

while fuel > 0:
    speed += 0.12
    fuel -= 1

print("Top speed = ", speed)

Here is what the above code is Doing:
1. We set the initial values of fuel and speed to 1000 and 0 respectively.
2. We then enter a while loop that will run as long as fuel is greater than 0.
3. Inside the while loop, we increase the speed by 0.12 and decrease the fuel by 1.
4. We then print the final value of speed.

Similar Posts