Ask Question

PHP Create a for loop that initialize with the variable $i = 10 The loop outputs $i as long as $i is greater than 1 using for loop Use echo statement to output $i Make sure to use operator based on the desired condition mentioned (increment $i+ + / decrement $i-) Make sure each line of code ends with a semi colon i. e;

+1
Answers (1)
  1. 29 June, 00:20
    0
    The PHP code is as follows


    for ($i = 10; $i>1; $i--)

    {

    echo $i.' ';

    }

    ?>

    Explanation:

    The code is self explanatory and doesn't require comments before it can easily understood.

    The program starts with a php opening tag
    And it ends with the closing tag?>

    The interpretation of the question is to print integer values from 10 to 1

    To do this, an iteration is needed.

    The above program makes use of a for loop iteration.

    Analysis;

    for (-> This shows that it is a for loop iteration

    $i = 10; - > Iterating variable $i is initialized to 10 (that is; printing will start at 10)

    $i>1; - > Iteration is valid while $i is greater than 1 (e. g. 2,3,4 ... 10)

    $i- - - > For every Iteration, decrease $i by 1

    ) - > End of Iterating condition

    echo $i.' '; - > This line prints the valid values of $i. In this case, the values of $i is from 10 and stops at 2

    The output is as follows

    10 9 8 7 6 5 4 3 2
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “PHP Create a for loop that initialize with the variable $i = 10 The loop outputs $i as long as $i is greater than 1 using for loop Use echo ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers