Why did you loop it in while(t--), did't quite understand that?

Why did you loop it in while(t–), did’t quite understand that?

@aposwal
We are required to work for t testcases as specified by the problem.
One way of running loop could be
int t;
cin >> t;
for(int i=0;i<t;i++) {
--
}
Or you could just use this method
while(t–) {
--
}

This will run t times as well and is much simpler to write. After t iterations , the value to variable t will become 0. Since 0 is considered equiavalant to false in C++ , the while loop will stop.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Tysm I was really confused. …