I've done something like this before



if you have a C++11 compiler, you can simply put that in place of your nested for loop, and returning from the lambda will break out of both loops