Since the next_album() function relies on global context it is impossible to successfully nest multiple loops as each loop will change the global context.
You will have to implement this using the object model instead. Alternatively you could save and restore the context, but to do that you will have to figure out all of what needs to be saved by understanding the workings of the next_album() loop itself.