Addede while loop for other 2 variables, added comments for better readability of code.