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

Do-while loop execution model in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Do-While Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple do-while loop
What is the output of this C# code snippet?
C Sharp (C#)
int count = 0;
do
{
    Console.Write(count + " ");
    count++;
} while (count < 3);
A0 1 2
B1 2 3
C0 1 2 3
DNo output
Attempts:
2 left
💡 Hint
Remember, do-while executes the loop body before checking the condition.
Predict Output
intermediate
2:00remaining
Do-while loop with condition false initially
What will this C# code print?
C Sharp (C#)
int x = 5;
do
{
    Console.WriteLine("Inside loop");
    x++;
} while (x < 5);
AInside loop
BNo output
C
Inside loop
Inside loop
DCompilation error
Attempts:
2 left
💡 Hint
Do-while runs the loop body at least once even if the condition is false.
🔧 Debug
advanced
2:00remaining
Identify the infinite loop in do-while
Which option causes an infinite loop when run?
C Sharp (C#)
int i = 0;
do
{
    Console.Write(i + " ");
} while (i < 3);
A
int i = 0;
do { Console.Write(i + " "); i++; } while (i &lt; 3);
B
int i = 0;
do { Console.Write(i + " "); i += 2; } while (i &lt; 3);
C
int i = 0;
do { i++; Console.Write(i + " "); } while (i &lt; 3);
D
int i = 0;
do { Console.Write(i + " "); } while (i &lt; 3);
Attempts:
2 left
💡 Hint
Check if the loop variable changes inside the loop body.
Predict Output
advanced
2:00remaining
Value of variable after do-while loop
What is the value of variable 'sum' after this code runs?
C Sharp (C#)
int sum = 0;
int n = 1;
do
{
    sum += n;
    n++;
} while (n <= 5);
A10
B15
C5
D0
Attempts:
2 left
💡 Hint
Sum numbers from 1 to 5 inclusive.
🧠 Conceptual
expert
2:00remaining
Do-while loop execution guarantee
Which statement best describes the execution behavior of a do-while loop in C#?
AThe loop body executes zero or more times depending on the condition.
BThe loop body executes only if the condition is true at the start.
CThe loop body executes at least once before the condition is checked.
DThe loop body executes exactly once regardless of the condition.
Attempts:
2 left
💡 Hint
Think about how do-while differs from while loop.