When I am using for loop, the code works perfectly fine. But when I write the same code using while loop, the code shows error. Why?
While loop does not work here
@saijaltripathy_e79096f8f1ec20e3 you have defined cst variable two times. First in line number 16 and then in line number 27 (wheny you used while loop) and you cannot defined the same variable two times.
Then how is it not showing any error when I’m using for loop?
@saijaltripathy_e79096f8f1ec20e3 you haven’t initialised CST again in the code where you used for loop. The scope of the variable in first loop ended with the loop and so again initialising it will not give any error.
How? I have written int cst = 1 inside the for loop. So I have re-initialized the value of cst here also, as in the case of while loop. Please explain.
@saijaltripathy_e79096f8f1ec20e3 you concept of scope of variable is not clear. First watch scope of the variable video.
Can you please tell the lecture no. which has this concept?
@saijaltripathy_e79096f8f1ec20e3 sorry I don’t have access to this. You can ask this in your whatsapp group of the batch
Ok thank you very much.
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.