How do I solve this infinite loop problem?

You were right. everything is working as intended now. Thanks!