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

Break statement behavior 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 exit the loop when the number is 5.

C Sharp (C#)
for (int i = 0; i < 10; i++) {
    if (i == [1]) {
        break;
    }
    Console.WriteLine(i);
}
Drag options to blanks, or click blank then click option'
A10
B5
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number other than 5 in the condition.
Forgetting to use the break statement.
2fill in blank
medium

Complete the code to break out of the while loop when count reaches 3.

C Sharp (C#)
int count = 0;
while (true) {
    Console.WriteLine(count);
    count++;
    if (count == [1]) {
        break;
    }
}
Drag options to blanks, or click blank then click option'
A3
B5
C0
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong number in the condition.
Not incrementing the count variable.
3fill in blank
hard

Fix the error in the code to break the loop when the character 'q' is found.

C Sharp (C#)
char[] letters = { 'a', 'b', 'c', 'q', 'd' };
foreach (char letter in letters) {
    if (letter == [1]) {
        break;
    }
    Console.WriteLine(letter);
}
Drag options to blanks, or click blank then click option'
A"q"
B"letter"
Cq
D'q'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes for a character.
Using a variable name instead of a character literal.
4fill in blank
hard

Fill both blanks to create a loop that breaks when the sum exceeds 10.

C Sharp (C#)
int sum = 0;
for (int i = 1; i <= 5; i++) {
    sum += i;
    if (sum [1] [2]) {
        break;
    }
}
Console.WriteLine(sum);
Drag options to blanks, or click blank then click option'
A>
B10
C<
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >.
Using 5 instead of 10.
5fill in blank
hard

Fill all three blanks to create a loop that breaks when the user inputs 'exit'.

C Sharp (C#)
string input;
do {
    Console.WriteLine("Type something (or 'exit' to quit):");
    input = Console.ReadLine();
    if (input [1] [2]) {
        [3];
    }
} while (true);
Drag options to blanks, or click blank then click option'
A==
B"exit"
Cbreak
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==.
Forgetting to use break to exit the loop.