I'm not sure if the lessons went over how to output the sum of a for loop in C#. Can anyone explain? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I'm not sure if the lessons went over how to output the sum of a for loop in C#. Can anyone explain?

The lessons haven't gone over while loops so I figure it wants a different answer.

4th Dec 2021, 10:36 PM
Robert Britton
Robert Britton - avatar
3 Answers
+ 2
You make viariable, give it a condition and increment or decrement variable untill condition doesn't meet requirements, in code it looks like this: for (int i = 0; i < 10; i++)
4th Dec 2021, 10:50 PM
cadbrooke
cadbrooke - avatar
+ 1
I got it!!! I had to end the statement with with a formula to output the sum. It was more than I first thought. for(int i = 1; i <= 10; i++) sum = sum + i;
4th Dec 2021, 11:09 PM
Robert Britton
Robert Britton - avatar
0
Then how would we output sum of all numbers generated?
4th Dec 2021, 10:52 PM
Robert Britton
Robert Britton - avatar