Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 5 using a loop.
C Sharp (C#)
for (int i = 1; i [1] 5; i++) { Console.WriteLine(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or >= will not run the loop correctly.
Using < will exclude 5 from printing.
✗ Incorrect
The loop should run while i is less than or equal to 5 to print numbers 1 to 5.
2fill in blank
mediumComplete the code to sum numbers from 1 to 10 using a loop.
C Sharp (C#)
int sum = 0; for (int num = 1; num [1] 10; num++) { sum += num; } Console.WriteLine(sum);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < will exclude 10 from the sum.
Using > or >= will cause the loop not to run as expected.
✗ Incorrect
The loop should include 10, so use <= to sum numbers 1 through 10.
3fill in blank
hardFix the error in the loop condition to print all elements of the array.
C Sharp (C#)
string[] fruits = {"apple", "banana", "cherry"};
for (int i = 0; i [1] fruits.Length; i++)
{
Console.WriteLine(fruits[i]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes an index out of range error.
Using > or >= will not enter the loop correctly.
✗ Incorrect
Array indexes go from 0 to Length - 1, so the loop should run while i < fruits.Length.
4fill in blank
hardFill both blanks to create a loop that prints even numbers from 2 to 10.
C Sharp (C#)
for (int num = [1]; num [2] 10; num += 2) { Console.WriteLine(num); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 will print odd numbers.
Using < will exclude 10 from printing.
✗ Incorrect
The loop starts at 2 and runs while num <= 10 to include 10.
5fill in blank
hardFill all three blanks to create a loop that prints numbers from 5 down to 1.
C Sharp (C#)
for (int i = [1]; i [2] 1; i [3]) { Console.WriteLine(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ++ will increase
i and cause an infinite loop.Using < instead of >= will skip printing 1.
✗ Incorrect
The loop starts at 5, runs while i >= 1, and decreases i by 1 each time.