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 01-19-2008, 11:33 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Big Grin lol, i made a never ending loop with arrays

i was playing around with arrays when i stumbled upon this lol

<?php

function br($num) {
for ($i=0; $i < $num;$i++) { echo "<br />"; }
}


//arrays

$fruits = array('apple','orange','banana','kiwi','plamgranit e');

while(list($key,$value) = each($fruits))

{
echo "Current:::::".br(1).current($fruits);
echo "[$key]:$value".br(1);
echo "Previous:::::".br(1).prev($fruits);

}


?>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-19-2008, 11:37 PM   #2 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 440
Thanks: 3
xenon is on a distinguished road
Default

Welcome to the programming world! Wanna see something kewler? Check this out:

PHP Code:
while(true) { } 
There ya have it. The easiest infinite loop :)
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-19-2008, 11:38 PM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Default

lol, thanks
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-19-2008, 11:43 PM   #4 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Default

but if i place this exit(); between the curleys then the loop will end.

but

this cant be ended. (unless a value is changed in a variable.)

while($i != 1 && $i=0) { echo "loop<br>"; }
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-19-2008, 11:55 PM   #5 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 440
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by sarmenhb View Post
but if i place this exit(); between the curleys then the loop will end.
exit breaks the execution of the entire script, not just the loop. So yeah, your "implementation" of an infinite loop is so much clever (exit can be put anywhere). But what's the point of it? infinite loop = no script (aka you can't actually have a working script and also an infinite loop at the same time). So why even bother trying to create an infinite loop?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-19-2008, 11:59 PM   #6 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
exit breaks the execution of the entire script, not just the loop. So yeah, your "implementation" of an infinite loop is so much clever (exit can be put anywhere). But what's the point of it? infinite loop = no script (aka you can't actually have a working script and also an infinite loop at the same time). So why even bother trying to create an infinite loop?
its usefull to showoff the non php programmers of the cool things us newbees can make (rofl)
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-20-2008, 12:00 AM   #7 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 440
Thanks: 3
xenon is on a distinguished road
Default

Right...sorry for taking away your enthusiasm then...my bad
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
sarmenhb (01-20-2008)
Old 01-20-2008, 12:01 AM   #8 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Right...sorry for taking away your enthusiasm then...my bad
none taken, i just got bored lol
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-21-2008, 08:45 AM   #9 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

how about (my personal fav, recursive infinate loops):
PHP Code:
lol();
function 
lol()
{
    return 
lol();

or even
PHP Code:
for (;;) 
{
    echo 
'lollll';

__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-21-2008, 11:02 AM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,239
Thanks: 3
Salathe is on a distinguished road
Default

Infinite loops from recursive functions/methods can be a particularly nasty trap to fall into! In a similar (erm, identical) vein to sketch's last code snippet here's another quick one-liner:
PHP Code:
for (;print 'lol';); 
__________________
salathe@php.net

Last edited by Salathe : 01-21-2008 at 11:54 AM.
Salathe is offline  
Reply With Quote
Old 01-21-2008, 12:10 PM   #11 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

Quote:
Infinite loops from recursive functions/methods can be a particularly nasty trap to fall into!
yep, idd it is lol.
you need to be VERY careful with recursion if you know how functions work then it should be apparent why. To cut a very long story short you risk crashing stuff as you are repeatedly calling the function thus producing function call overhead for each funcion being called, thus using up alot of memory.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-21-2008, 12:54 PM   #12 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

Infinite loops are bad I crashed my computer thrice because I could not find the loop -.-
TlcAndres is offline  
Reply With Quote
Old 01-21-2008, 03:00 PM   #13 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

i remember a fellow student at uni do it once whilst the lab tutor was watching, luckly it didnt crash the computer, he laughed for quite a while, so did I come to think of it hehe
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-21-2008, 04:21 PM   #14 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,042
Thanks: 193
Orc is on a distinguished road
Default

Brilliant thread, I must say. :P
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-22-2008, 09:26 PM   #15 (permalink)
The Wanderer
 
Join Date: Jan 2008
Location: Nottingham
Posts: 7
Thanks: 1
Daniel is on a distinguished road
Default

PHP Code:
<?php while(phpinfo()); ?>
has to be my favourite. Plenty of information there, (p.s. No need to put an ob_start(); before that)
Send a message via MSN to Daniel
Daniel is offline  
Reply With Quote
Old 01-22-2008, 09:31 PM   #16 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

Who'd have thought such a thread would have become so popular ! You folks do surprise me sometimes.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-22-2008, 11:10 PM   #17 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,042
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Who'd have thought such a thread would have become so popular ! You folks do surprise me sometimes.
Agreed. (chars)
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-24-2008, 03:54 PM   #18 (permalink)
The Wanderer
 
cherries's Avatar
 
Join Date: Oct 2007
Posts: 20
Thanks: 0
cherries is an unknown quantity at this point
Default

PHP Code:
<?php while(1) print 'lol'?>
cherries is offline  
Reply With Quote
Old 01-24-2008, 08:51 PM   #19 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Default

haha, yet another popular treath by me.


Invisible Loop

for(;;) { echo "<br/>"; }
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-24-2008, 11:48 PM   #20 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 265
Thanks: 2
TlcAndres is on a distinguished road
Default

PHP Code:

while($total == 1)
{
   ++
$x;
   
$total = ((10 pow($x,3) + pow($x,2) + 10 $x 8) / (pow($x,2) + 1)) - 10 $x 7;
   echo (
'foo');


(don't quote me on the math, haven't tried it)
TlcAndres 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 04:56 AM.

 
     

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