0
0
Fluttermobile~10 mins

Control flow (if, for, while, switch) in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a number is positive.

Flutter
if (number [1] 0) {
  print('Positive');
}
Drag options to blanks, or click blank then click option'
A<
B==
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes wrong logic.
Using '==' checks only for zero.
2fill in blank
medium

Complete the for loop to print numbers from 0 to 4.

Flutter
for (int i = 0; i [1] 5; i++) {
  print(i);
}
Drag options to blanks, or click blank then click option'
A<
B>
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' prints 0 to 5, which is one extra.
Using '>' causes the loop to never run.
3fill in blank
hard

Fix the error in the while loop condition to stop at 3.

Flutter
int count = 0;
while (count [1] 3) {
  print(count);
  count++;
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' excludes 3 from the loop.
Using '>' causes the loop to never run.
4fill in blank
hard

Fill both blanks to create a for loop that prints even numbers from 2 to 6.

Flutter
for (int i = [1]; i [2] 6; i += 2) {
  print(i);
}
Drag options to blanks, or click blank then click option'
A2
B<
C<=
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' excludes 6 from printing.
Starting at 1 prints odd numbers.
5fill in blank
hard

Fill all three blanks to create a switch statement that prints the day name for 1, 2, or 3.

Flutter
switch(day) {
  case [1]:
    print('Monday');
    break;
  case [2]:
    print('Tuesday');
    break;
  case [3]:
    print('Wednesday');
    break;
  default:
    print('Invalid day');
}
Drag options to blanks, or click blank then click option'
A1
B2
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 causes the default case to run.
Mixing numbers changes the output.