TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-11-2008, 03:22 PM   #1 (permalink)
The Wanderer
Newcomer 
 
Join Date: Feb 2008
Posts: 6
Thanks: 2
pabin is on a distinguished road
Wink Need help on nested loop!

Could somebody overhere expalin how nested loop works because i am quite confuse on this issue?
pabin is offline  
Reply With Quote
Old 05-11-2008, 08:31 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Nested:

1) A process or activity self-contained within a larger entity, that retains its identity and characteristics for reporting and analysis.

2) Nested is the seventh studio album by Bronx-born singer, songwriter, and pianist Laura Nyro, released in 1978 by Columbia Records.

What in particular about it are you having trouble with?
-m
delayedinsanity is offline  
Reply With Quote
Old 05-11-2008, 11:55 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

A nested loop is a loop inside a loop. For instance, if you are reading posts on a forum sequentially, you would read:
Topic 1
Post 1
Post 2
Post 3
Topic 2
Post 1
Post 2
Post 3
So on the so forth.

If you want a purely programmatic example, run this code.
PHP Code:
<?php
for($i=0;$i<10;$i++)
{
    echo 
"Main Level $i - ";
    for(
$j=0;$j<10;$j++)
    {
        echo 
"Sub-Level $j - ";
    }
    echo 
"<br />";
}
?>
Here is what it will output:
http://justanotherportfolio.com/nest.php
__________________

Village Idiot is offline  
Reply With Quote
Old 05-12-2008, 12:00 AM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

A nested loops is a loop that has a loop within it. First of all the outer loop's first iteration triggers the inner loop then the inner loop continues until completion, then the outer loop cycles again thus causing the inner again to trigger again.

put into a simple example:

PHP Code:
for($i=0;$i 10$i++)
{
    echo 
'Line '$i 1' ';
    for(
$j=0$j 5$j++)
    {
        echo 
$j;
    }
    echo 
'<br />';

outputs :
Code:
Line 1 01234
Line 2 01234
Line 3 01234
Line 4 01234
Line 5  01234
Line 6 01234
Line 7 01234
Line 8 01234
Line 9 01234
Line 10  01234
basically the first loop out puts : 'Line 1' then the nested loop starts and echos numbers 0-4, then the first loop echos 'Line 2' then triggers the nested loop again and the cycle continues until the first loop finishes.

hope i made that helps
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-12-2008, 10:27 AM   #5 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

damn village beat me! lol the code looks similar aswell, anyway both posts should help you understand
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:09 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design