Please explain the dry run of else statement

I m not getting how the even row has printed. In the true expression of while loop we have (col<=row-2) so how 1001 will get printed if row=4

@Tanvi-Varshney-250726472940778

col = 1;
cout << "1"; //this will print "1"
while (col <= row-2) {
    cout << "0";
    col = col + 1;
}   //this loop will run "row-2", ie "2" times 
// so now the output is "100"
cout << "1"; // this will print the last 1, making the output "1001"
1 Like

@Tanvi-Varshney-250726472940778 please mark the doubt as resolved in case of no further queries.

Thnku to clear my doubt

1 Like

@Tanvi-Varshney-250726472940778 mark the doubt as resolved

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.