Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:45:38+00:00 2026-05-25T20:45:38+00:00

Working on a homework assignment and am stuck with this task: Create a loop

  • 0

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.

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.

EDIT: Here is my own solution, curious if this is the best method? Seems simple enough.

if ( $num1 < $num2 )
for ($i=$num1+1; $i<$num2; $i++)
    echo $i . "<br />";
else
for ($i=$num2+1; $i<$num1; $i++)
    echo $i . "<br />";

Here is some of the assignment thus far:

<?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 <br />";
else
    echo "First number is an EVEN Number </br />";
if( $odd = $num2%2 )
    echo "Second number is an ODD Number <br />";
else
    echo "Second number is an EVEN Number </br />";
//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 <br />";
elseif ( $num1 > $num2 )
        echo "First number is greater than second number <br />";
    else
        echo "First number is less than second number <br />";

//Create a loop structure to display all integer values BETWEEN the smaller and larger number provided

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:45:39+00:00Added an answer on May 25, 2026 at 8:45 pm
    if ( $num1 < $num2 )
    for ($i=$num1+1; $i<$num2; $i++)
    echo $i . "<br />";
    else
    for ($i=$num2+1; $i<$num1; $i++)
    echo $i . "<br />";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a homework assignment and I am thoroughly stuck. I
I'm working on a homework assignment that asks me to create a calculator that
I am working on my last homework assignment for COBOL this semester and I
I'm working on a homework assignment where I must manually optimize a nested loop
I am working on my homework assignment and I am completely stuck! What I
I'm working on a homework assignment in which I'm required to use char arrays
I'm working on a homework assignment (a project), for which one criterion is that
I'm working on this homework that's kind of confusing me... I am provided with
I'm working on a homework assignment for my C++ class. The question I am
I'm working on a homework assignment for my object oriented design class, and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.