IF we replace the first ‘while’ loop
in the second ‘for’ loop
with an ‘if’ statement ,
Would the logic be still correct?
Replacing 'while' with 'if'
No it will not be correct. if will only check one condition and move further. while will check again and again until condition is not satisfied. To understand well, dry run with some example case.
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.