Skip to content

Nested range Bug #125016

@chlovec

Description

@chlovec

Bug report

Bug description:

def nested_range_bug(self, word: str) -> int:
        word_len: int = len(word)
        for left in range(len(word) - 1, - 1, -1):
            for index in range(1, min(10, word_len - left)):
                return left

    def test_my_word(self) -> None:
        actual_left = self.nested_range_bug("band")
        self.assertEqual(3, actual_left)

When using a nested range in two nested loops and the range in the inner loop is started at one, python skips processing of the the first iteration of the outer loop.
In the code example above, it's nested_range_bug is expected to return 3 but it returns 2 instead.

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions