Explain the dry run of else statement

I have a doubt how the even row is getting printed.
In the else statement, the true expression of while is (col<=row-2) how will it print 1001 if row=4

Hey @Tanvi-Varshney-250726472940778,

  1. As you have noticed a common pattern in the even rows:
    i.e. first and the last col is 1 as rest all the values are 0.

  2. The number of values or column per row is equal to the row number.
    i,e row 1: 1 element
    row 2: 2 element
    so on…

So, if row is even:

  1. print 1 for col 0
  2. (col<=row-2)
    This means:
    for col 1 to row-2 i.e. the second last column print 0
  3. print 1 for row-1 col i.e. the last col.

Hope, this would help.

2 Likes

@S18ML0016
thanks bhaiya for ur awesome reply

Thnku bhaiya to resolve my doubt

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.