Loop to get the manager details

How to achieve this functionality ?

If user's manager band is between 0 to 3 then consider manager details of that user,
if user manager is more than 3 then manager's manager(next linemanager) band should be checked and if it is not between 0 to 3 then again check for next further line manager.
This process should be repeated until we get the any of the manager band as between 0,1,2,3.

  Discussion posts and replies are publicly visible