In that case one should go all the way, i.e. only check 4 plies back (so no for loop).I have looked into over hundreds of testgames recently, and I couldn't even find a single case of repetition in a cycle of other than 4 plies. In human games, this may happen more frequently, but in engine-engine games it seems rather uncommon. Think about it.
Perhaps it is sensible to do this with a depth restriction. In that case the occasionally incorrectly evaluated nodes will be researched at greater depth. In that way Stockfish will not make obvious blunders.