Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a loop structure to display all integer values BETWEEN the smaller and larger number provided?
    primarykey
    data
    text
    <p>Working on a homework assignment and am stuck with this task: Create a loop structure to display all integer values BETWEEN the smaller and larger number provided. Not looking for just an answer in code form. Would appreciate an explanation as to how and why it works.</p> <p>Data for the variables comes from users inputting a value between 1 and 100. I assume I will need a loop that will start with the lower of the two variables, count until it reaches the higher of the two variables, echo each integer in between and stop running. I am at a loss as to how to achieve this. I will also need a loop that will display only integers at certain intervals between the two numbers, such as only the multiples of five. </p> <p>EDIT: Here is my own solution, curious if this is the best method? Seems simple enough.</p> <pre><code>if ( $num1 &lt; $num2 ) for ($i=$num1+1; $i&lt;$num2; $i++) echo $i . "&lt;br /&gt;"; else for ($i=$num2+1; $i&lt;$num1; $i++) echo $i . "&lt;br /&gt;"; </code></pre> <p>Here is some of the assignment thus far:</p> <pre><code>&lt;?php //Assign user input to variables $num1 = $_GET['firstNum']; $num2 = $_GET['secondNum']; //Determine if each number is odd or even, display results if( $odd = $num1%2 ) echo "First number is an ODD Number &lt;br /&gt;"; else echo "First number is an EVEN Number &lt;/br /&gt;"; if( $odd = $num2%2 ) echo "Second number is an ODD Number &lt;br /&gt;"; else echo "Second number is an EVEN Number &lt;/br /&gt;"; //Determine if the first number is larger than, smaller than, or equal to the second number, display results if ( $num1 == $num2 ) echo "First number is equal to second number &lt;br /&gt;"; elseif ( $num1 &gt; $num2 ) echo "First number is greater than second number &lt;br /&gt;"; else echo "First number is less than second number &lt;br /&gt;"; //Create a loop structure to display all integer values BETWEEN the smaller and larger number provided ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload