Nicholas T. answered 04/07/22
Student Experienced in C++ Assignments
You have a while loop with while(condition) and are interested in fetching the last iteration of the loop and store it in some data to be executed once you exit the loop.
One method is to check the condition after all your processing is done.
Another option if you need to keep all the data in every iteration is to use some kind of container like a vector and push the data onto that container in every iteration.
To get the result of the last iteration, you fetch the last element of the vector.
This has the additional benefit that you keep the information from every iteration.
The drawback is that it can waste a lot more space.