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

Do-while 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 start a do-while loop that prints "Hello" once.

C Sharp (C#)
do {
    Console.WriteLine("Hello");
} while ([1]);
Drag options to blanks, or click blank then click option'
Afalse
Btrue
C0
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' causes an infinite loop.
Using '0' or 'null' is invalid for a boolean condition.
2fill in blank
medium

Complete the code to repeat the loop while the variable count is less than 3.

C Sharp (C#)
int count = 0;
do {
    Console.WriteLine(count);
    count++;
} while ([1]);
Drag options to blanks, or click blank then click option'
Acount > 3
Bcount >= 3
Ccount == 3
Dcount < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count > 3' causes the loop to never run.
Using 'count == 3' runs only when count equals 3, which is after the loop.
3fill in blank
hard

Fix the error in the do-while loop condition to compile correctly.

C Sharp (C#)
int i = 0;
do {
    Console.WriteLine(i);
    i++;
} while ([1]);
Drag options to blanks, or click blank then click option'
Ai < 5
Bi = 5
Ci++ < 5
Di => 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' assigns instead of compares.
Using '=>' is invalid syntax here.
4fill in blank
hard

Fill both blanks to create a do-while loop that prints numbers 1 to 3.

C Sharp (C#)
int num = 1;
do {
    Console.WriteLine(num);
    num[1]1;
} while (num [2] 4);
Drag options to blanks, or click blank then click option'
A++
B--
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--' decreases the number, causing an infinite loop.
Using '>' in the condition stops the loop immediately.
5fill in blank
hard

Fill all three blanks to create a do-while loop that prints even numbers from 2 to 6.

C Sharp (C#)
int val = [1];
do {
    Console.WriteLine(val);
    val [2] 2;
} while (val [3] 8);
Drag options to blanks, or click blank then click option'
A2
B+=
C<
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' decreases the value, causing an infinite loop.
Using '>' in the condition stops the loop too early.