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 813033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:17:41+00:00 2026-05-15T01:17:41+00:00

The code below shows nested while loops, but it’s not the very efficient. Suppose

  • 0

The code below shows nested while loops, but it’s not the very efficient. Suppose I wanted to extend the code to include 100 nested while loops. Is there a better way to accomplish this task?

<?php 

$count = 1;

 $num = 1;
 $options=3;
 while ( $num <=$options ) 
    { 
echo "(".$num . ") "; 

    $num1 = 1; 
    $options1=3;
    while ( $num1 <=$options1 ) 
    { 
    echo "*".$num1 . "* "; 

        $num2 = 1; 
        $options2=3;
        while ( $num2 <=$options2 ) 
        { 
        echo "@".$num2 . "@ ";  

            $num3 = 1; 
            $options3=3;
            while ( $num3 <=$options3 ) 
            { 
            echo $num3 . " ";   
            $num3++; 
            $count++;
            }

        echo "<br />";
        $num2++; 
        }

    echo "<br />";
    $num1++; 
    }

echo "<br />";
$num++; 
} 
  echo $count;
 ?>
  • 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-15T01:17:41+00:00Added an answer on May 15, 2026 at 1:17 am

    It’s perfectly efficient enough if the loops need to be nested.

    As others have said, recursion would allow you to “nest” different levels within each other more elegantly, and the level of nesting could be controlled dynamically rather than being hard-coed into your program – but if you find your design requires you to nest 100 loops, then your design is almost certainly completely mad.

    (However, in the specific example you give there is no need for any loops (or recursion) at all. As all the loops are of constant length, you can precalculate the result and just echo a single constant string. I presume this is a hyporthetical example rather than the actual code you wish to write?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Please see the code below: #include <windows.h> int main(int argc, char* argv[]) { HANDLE
Hi I have writen an Nested Structure in C# . Find the code snippet
I am using jquery to create a custom dropdown with the code below. I
I'm a bit stuck trying to get my code to output correctly, see below.
I am taking a principles of programming languages course right now but I cannot
I have this PHP code I am trying to integrate with the html layout
I have a nested table arrangement for displaying data. I want the nested table
I'm using VS2008, and I have a project that will not start when I
I'm having an issue with the HTML below: <html> <body> <p style=font-size: large> Some
On a blank winform code can be added to show lines that intersect (crosshairs)

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.