Why this code giving different answer when i = 1 . Please give me logical reason . And how to that we have to put i=0 or i=1 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why this code giving different answer when i = 1 . Please give me logical reason . And how to that we have to put i=0 or i=1 ?

https://code.sololearn.com/cY47hS27lI1K/?ref=app

8th Mar 2022, 8:40 AM
Abhay mishra
Abhay mishra - avatar
1 Answer
+ 1
With the same inputs, 👉for(i=1;i<=terms-2;i++) { Gives the same results in your code as 👉for(i=0;i<=terms-3;i++) { But if you don't change terms-3 then you get 1 less result (1 less loop). The answer to should we start at i=0 or at i=1 is: depends on your logic. Many times you will want to start at i=0, eg to access arrays, or to not multiply a variable on the first loop. Most of the time my for loops start at i=0.
8th Mar 2022, 8:55 AM
HungryTradie
HungryTradie - avatar