Loops – For, While, Do While (Exercise) – Learn C#

8  comments

This is an exercise for this YouTube video.

Happy learning and good luck!

[qsm quiz=4]

 

Assignment: Write code which will sum numbers from 0 to n (inclusively) where n is your made up number.

 

Click to see the answer
int sum = 0;
int n = 5;
for (int i = 0; i <= n; i++)
{
    sum += i;
}
Console.WriteLine(sum);

 

 

 

 

 

About the author 

Matt Rešetár

Matt is an app developer with a knack for teaching others. Working as a Flutter Developer at LeanCode and a developer educator, he is set on helping other people succeed in their Flutter app development career.

You may also like

Flutter UI Testing with Patrol

Flutter UI Testing with Patrol
  • I don’t really get why we need a do while loop. Ok, it runs the code before checking the condition, so it runs at least once. I got that, just a bit weird for me, maybe because I’m coming from Python. Great tutorials btw. Keep up the good work.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    >