Looks quite elegant :-) You should probably use else-if instead of ifs though, otherwise it is (immediately) complicated to e.g. count the number of instructions you execute.
Personally, my inclination would be to rewrite the loop to tighten it up. But maybe the point was to show how quickly and dirtily one can do this... it definitely looks quick and dirty.