GDQuest / GDQuest/learn-gdscript
Lesson 18, the for-loop is NOT doing the same as the while-loop
- Dominant language
- GDScript
- Stars
- 2.8k
- Forks
- 235
- PR merge metrics
- No merged PRs in 30d
Description
The while-loop checks the current position each time, so it works for all cells on the board. It only loops the required amount to reach the right edge.
The for-loop always walks board_size.x times to the right and therefore only works for starting positions on the left edge of the board. If the starting cell is at least one column away from the left edge, it over shoots.
It *could* be remedied by changing the loop to this:
```
for number in range(board_size.x - cell.x - 1):
cell.x += 1
```
But I doubt you could still call that one a little simpler than the while-loop variant.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.