David Wees came up with this challenge. Determine what algorithm this code emulates. You will find the answer more informative if you create a table to see the pattern of moves the code makes. The table can then be used to introduce the algorithm formally to your students. Or better yet, get them to build their own tables from the code. Try a range of integers to test the code. What patterns exist?
I will post my answer in a couple of days.Follow @stefras