Skip to content

Lesson 17. Introduction to For Loops: Clarification needed: "for" and "while" loops are only identical if cell.x starts at 0 #1327

@AbrahimIII

Description

@AbrahimIII

In the section "Using a for loop instead of while loop", the text implies that the two code snippets are identical.

However, they only behave identically if cell.x is initialized to 0 before the loop runs. If cell.x starts at any other value, the for loop will overshoot the board_size.x - 1 limit because it executes a fixed number of times, whereas the while loop evaluates the condition dynamically on every iteration.

Suggested fix:
Add a brief note mentioning that this simplification assumes cell.x starts at 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentIssues with the lessons, practices, including their code examples

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions