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

  • SEARCH
  • Home
  • 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 8627735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:21:25+00:00 2026-06-12T08:21:25+00:00

When i write code i have to use loops e.g. $six = 6; for

  • 0

When i write code i have to use loops e.g.

$six = 6;
for ($i = $six; $i > 1; $i--) {
   echo $i."<br>";
}

outputs

6
5
4
3
2

i need it to output 1 as well i know i can do for ($i = 6; $i >= 1; $i--)

or
for ($i = $six+1; $i > 1; $i--) in evaluation but its confusing so muchg!
in fact i always confused when using for statement.

EDIT: its confusing because i dont like to think backwards.. id like to run loop not while condition $six > 1 is true, but rather before condition like $six = 1 is meet.

the opposite way i guess

loop_before ($six==1) {
   echo $six.<br />;
   $six--;
}

well even this one wont output 654321… guess i just need to go back to school.
got to do

loop_before ($six<1) {
   echo $six.<br />;
   $six--;
}
  • 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-06-12T08:21:26+00:00Added an answer on June 12, 2026 at 8:21 am

    This confusion may not be only for for() statement but for other types of loop. You can use $six >= 1 or $six > 0

    Example 1

    $six = 6;
    do {
        echo $six . "<br>";
        $six --;
    } while ( $six >= 1 );
    

    Example 2

    $six = 6;
    for($i = $six; $i >= 1; $i --) {
        echo $i . "<br>";
    }
    

    Example 3

    $six = 6;
    while ( $six >= 1 ) {
        echo $six . "<br>";
        $six --;
    }
    

    Lastly you might decide not to even use any default PHP loop

    $six = 6;
    __loop($six);
    
    function __loop($x) {
        echo $x . "<br>";
        $x --;
        ($x < 1) ? $x : __loop($x);
    }
    

    They would all return the same thing

    6
    5
    4
    3
    2
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write the output of the code I have to a file
Question simple and quick: I have started to use Netbeans to write some code
I have write this code but it does work only if I am already
I have this code to write to a file, it works perfect but I
when I write Python code from the interpreter I can type dir() to have
I have a text editor in which a user can write HTML code. I
Sometimes I have to write code that alternates between doing things and checking for
I have been trying to write some code in Scala to read a file
So far I have managed to write some code that should print the source
I have some MVC2 code that loops a collection of type Product held within

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.