Fix issue #17999 (Unused variables inside `for` are not detected)

Fix issue #17999 (Unused variables inside `for` are not detected)