While and do while loops do not behave as you would expect when used with Cypress, so it's recommended to avoid them
https://www.youtube.com/watch?v=5Z8BaPNDfvA▾
I highly recommend Cypress Recurse package instead
https://github.com/bahmutov/cypress-recurse