util: move var declaration before loop to fix MSVC error