Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 0 to 4 using a for loop.
C Sharp (C#)
for (int i = 0; i [1] 5; i++) { Console.WriteLine(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes the loop to run one extra time.
Using > or >= makes the loop not run at all.
✗ Incorrect
The for loop runs while i is less than 5, so it prints 0 to 4.
2fill in blank
mediumComplete the code to sum numbers from 1 to 5 using a for loop.
C Sharp (C#)
int sum = 0; for (int num = 1; num [1] 5; num++) { sum += num; } Console.WriteLine(sum);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < excludes 5, so sum is less than expected.
Using > or >= causes the loop not to run.
✗ Incorrect
The loop includes 5 by using <=, so sum is 1+2+3+4+5 = 15.
3fill in blank
hardFix the error in the for loop condition to count down from 5 to 1.
C Sharp (C#)
for (int i = 5; i [1] 1; i--) { Console.WriteLine(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or <= causes the loop to never run.
Using == runs the loop only once.
✗ Incorrect
The loop runs while i is greater than or equal to 1, counting down.
4fill in blank
hardFill both blanks to create a for loop that prints even numbers from 2 to 10.
C Sharp (C#)
for (int i = [1]; i [2] 10; i += 2) { Console.WriteLine(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 prints odd numbers.
Using < excludes 10 from printing.
✗ Incorrect
The loop starts at 2 and runs while i is less than or equal to 10, printing even numbers.
5fill in blank
hardFill all three blanks to create a for loop that prints the squares of numbers from 1 to 5.
C Sharp (C#)
for (int [1] = 1; [2] [3] 5; [1]++) { Console.WriteLine([1] * [1]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
Using < excludes 5 from the loop.
✗ Incorrect
The loop variable i starts at 1 and runs while it is less than or equal to 5, printing squares.