0
0
C Sharp (C#)programming~10 mins

For loop execution model in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A<=
B>
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes the loop to run one extra time.
Using > or >= makes the loop not run at all.
2fill in blank
medium

Complete 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'
A<=
B<
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < excludes 5, so sum is less than expected.
Using > or >= causes the loop not to run.
3fill in blank
hard

Fix 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'
A>=
B<
C<=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or <= causes the loop to never run.
Using == runs the loop only once.
4fill in blank
hard

Fill 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'
A2
B<
C<=
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 prints odd numbers.
Using < excludes 10 from printing.
5fill in blank
hard

Fill 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'
Ai
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
Using < excludes 5 from the loop.