0
0
PHPprogramming~10 mins

Do-while loop execution model in PHP - 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 in PHP.

PHP
<?php
do [1] {
    echo "Hello";
} while (false);
Drag options to blanks, or click blank then click option'
Awhile
Bdo
Cfor
Dforeach
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'while' instead of 'do' to start the loop.
Using 'for' or 'foreach' which are different loop types.
2fill in blank
medium

Complete the code to correctly write the condition part of a do-while loop.

PHP
<?php
do {
    echo "Count: $i\n";
    $i++;
} while ([1] < 5);
Drag options to blanks, or click blank then click option'
A$i
B$count
C$j
D$num
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable not defined or incremented in the loop.
Using a variable that does not control the loop condition.
3fill in blank
hard

Fix the error in the do-while loop syntax by completing the missing part.

PHP
<?php
$i = 0;
do {
    echo $i . "\n";
    $i++;
} [1] ($i < 3);
Drag options to blanks, or click blank then click option'
Aif
Bdo
Cwhile
Dfor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'do' again after the block instead of 'while'.
Using 'if' or 'for' which are not valid here.
4fill in blank
hard

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

PHP
<?php
$i = 1;
do {
    echo $i . "\n";
    $i[1]1;
} [2] ($i <= 3);
Drag options to blanks, or click blank then click option'
A++
B--
Cwhile
Ddo
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--' to decrement instead of increment.
Using 'do' instead of 'while' after the block.
5fill in blank
hard

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

PHP
<?php
$num = 2;
do {
    echo $num . "\n";
    $num [1] 2;
} [2] ($num [3] 8);
Drag options to blanks, or click blank then click option'
A+=
Bwhile
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '<' in the condition.
Using '+' instead of '+=' for increment.