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

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 while loop that runs as long as the variable count is less than 5.

C Sharp (C#)
int count = 0;
while ([1])
{
    Console.WriteLine(count);
    count++;
}
Drag options to blanks, or click blank then click option'
Acount >= 5
Bcount > 5
Ccount == 5
Dcount < 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or >= instead of <
Using == which runs only when count equals 5
2fill in blank
medium

Complete the code to stop the while loop when number reaches 10.

C Sharp (C#)
int number = 0;
while (number [1] 10)
{
    Console.WriteLine(number);
    number++;
}
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or >= which never becomes true at start
Using == which runs only once when number is 10
3fill in blank
hard

Fix the error in the while loop condition to avoid an infinite loop.

C Sharp (C#)
int i = 0;
while (i [1] 5)
{
    Console.WriteLine(i);
    // Missing increment
}
Drag options to blanks, or click blank then click option'
A>=
B>
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which never becomes false if i starts at 0
Forgetting to increment i inside the loop
4fill in blank
hard

Fill both blanks to create a while loop that prints numbers from 1 to 5.

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

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

C Sharp (C#)
int val = [1];
while (val [2] 10)
{
    Console.WriteLine(val);
    val [3] 2;
}
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 < 10 misses printing 10
Using += 1 prints all numbers, not just even