22
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
int total = 0;
8
int num = 1;
9
10
// here is a while loop
11
while(num <= 100){
12
total = total + num;
13
num = num + 1;
14
}
15
Console.WriteLine("Answer calculated in a while loop: " + total);
16
17
int myTotal = 0;
18
// TODO: write it out in for loop, it is ok to reuse the total and num variables
19
20
Console.WriteLine("Answer calculated in a for loop: " + myTotal);
21
}
22
}
Cached Result