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

Nested loop execution 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 1 to 3 using a nested loop.

C Sharp (C#)
for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= [1]; j++) {
        Console.WriteLine(j);
    }
}
Drag options to blanks, or click blank then click option'
Ai
B5
C3
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using the outer loop variable 'i' as the inner loop limit causes incorrect output.
Setting the inner loop limit to 5 prints extra numbers.
2fill in blank
medium

Complete the code to print a 3x3 grid of stars (*) using nested loops.

C Sharp (C#)
for (int row = 1; row <= 3; row++) {
    for (int col = 1; col <= [1]; col++) {
        Console.Write("*");
    }
    Console.WriteLine();
}
Drag options to blanks, or click blank then click option'
A5
Bcol
Crow
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the outer loop variable 'row' as the inner loop limit causes inconsistent stars per row.
Setting the inner loop limit to 5 prints too many stars.
3fill in blank
hard

Fix the error in the nested loops to correctly print pairs of numbers.

C Sharp (C#)
for (int x = 1; x <= 2; x++) {
    for (int y = 1; y <= [1]; y++) {
        Console.WriteLine($"({x}, {y})");
    }
}
Drag options to blanks, or click blank then click option'
Ax
B2
C3
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Using the outer loop variable 'x' as the inner loop limit causes incorrect pairs.
Setting the inner loop limit to 3 prints extra pairs.
4fill in blank
hard

Fill both blanks to create a nested loop that prints a multiplication table for 1 to 3.

C Sharp (C#)
for (int i = 1; i <= [1]; i++) {
    for (int j = 1; j <= [2]; j++) {
        Console.Write($"{i * j} ");
    }
    Console.WriteLine();
}
Drag options to blanks, or click blank then click option'
A3
B5
C4
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using different limits for the loops causes incomplete or extra rows/columns.
Setting limits higher than 3 prints a larger table than required.
5fill in blank
hard

Fill all three blanks to create a nested loop that prints a right-angled triangle of stars.

C Sharp (C#)
for (int row = 1; row <= [1]; row++) {
    for (int col = 1; col <= [2]; col++) {
        if (col <= [3]) {
            Console.Write("*");
        }
    }
    Console.WriteLine();
}
Drag options to blanks, or click blank then click option'
A5
Brow
Ccol
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'col' instead of 'row' in the if condition prints incorrect patterns.
Setting different limits for loops causes uneven triangle shapes.