Unable to understand the solution of the question given in the link

https://online.codingblocks.com/player/11453/content/38?s=1809

Unable to understand the solution in the video of The Glittering Caves of Aglarond problem after the while loop.