Replace foreach loops and improve code style in composite
Summary: Replaces foreach loops with modern for loops and improve code style overall.
Test Plan: Auto tests pass as before and manually in X and Wayland sessions.
Reviewers: KWin
Subscribers: zzag, kwin
Tags: KWin
Maniphest Tasks: T11071
Differential Revision: https://phabricator.kde.org/D23011