Why do we declare sum=0 in loops? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do we declare sum=0 in loops?

Loops

14th Nov 2020, 11:32 AM
Anas kayani
Anas kayani - avatar
1 Answer
+ 2
Hi there, your question is unclear. It also misses the tag to a language and a piece of code about your doubt https://www.sololearn.com/discuss/1316935/?ref=app Anyway you initialize sum with the value 0 because then you are gong to do sum = sum + something And if your sum is not initialized, you are starting from a random amount.
14th Nov 2020, 11:46 AM
Davide
Davide - avatar