 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
Advertisement
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
01-20-2008, 12:33 AM
|
#1 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
|
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);
}
?>
|
|
|
01-20-2008, 12:37 AM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
|
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.
|
|
|
|
01-20-2008, 12:38 AM
|
#3 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
|
lol, thanks
|
|
|
01-20-2008, 12:43 AM
|
#4 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
|
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>"; }
|
|
|
01-20-2008, 12:55 AM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
|
Quote:
Originally Posted by sarmenhb
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.
|
|
|
|
01-20-2008, 12:59 AM
|
#6 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
|
Quote:
Originally Posted by xenon
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)
|
|
|
01-20-2008, 01:00 AM
|
#7 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
|
Right...sorry for taking away your enthusiasm then...my bad 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
|
The Following User Says Thank You to xenon For This Useful Post:
|
|
01-20-2008, 01:01 AM
|
#8 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
|
Quote:
Originally Posted by xenon
Right...sorry for taking away your enthusiasm then...my bad 
|
none taken, i just got bored lol
|
|
|
01-21-2008, 09:45 AM
|
#9 (permalink)
|
|
The Frequenter
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
|
how about (my personal fav, recursive infinate loops):
PHP Code:
lol(); function lol() { return lol(); }
or even
PHP Code:
for (;;) { echo 'lollll'; }
__________________
|
|
|
|
01-21-2008, 12:02 PM
|
#10 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 713
Thanks: 2
|
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';);
__________________
Last edited by Salathe : 01-21-2008 at 12:54 PM.
|
|
|
|
01-21-2008, 01:10 PM
|
#11 (permalink)
|
|
The Frequenter
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
|
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.
__________________
|
|
|
|
01-21-2008, 01:54 PM
|
#12 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 265
Thanks: 2
|
Infinite loops are bad I crashed my computer thrice because I could not find the loop -.-
|
|
|
|
01-21-2008, 04:00 PM
|
#13 (permalink)
|
|
The Frequenter
Join Date: Oct 2007
Location: Manchester, UK
Posts: 469
Thanks: 26
|
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
__________________
|
|
|
|
01-21-2008, 05:21 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
|
Brilliant thread, I must say. :P
__________________
Wax on, Wax off
|
|
|
|
01-22-2008, 10:26 PM
|
#15 (permalink)
|
|
The Wanderer
Join Date: Jan 2008
Location: Nottingham
Posts: 7
Thanks: 1
|
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)
|
|
|
01-22-2008, 10:31 PM
|
#16 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 1,587
Thanks: 72
|
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.
|
|
|
01-23-2008, 12:10 AM
|
#17 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 824
Thanks: 163
|
Quote:
Originally Posted by Wildhoney
Who'd have thought such a thread would have become so popular  ! You folks do surprise me sometimes.
|
Agreed. (chars)
__________________
Wax on, Wax off
|
|
|
|
01-24-2008, 04:54 PM
|
#18 (permalink)
|
|
The Wanderer
Join Date: Oct 2007
Posts: 20
Thanks: 0
|
PHP Code:
<?php while(1) print 'lol'; ?>
|
|
|
|
01-24-2008, 09:51 PM
|
#19 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 258
Thanks: 39
|
haha, yet another popular treath by me.
Invisible Loop
for(;;) { echo "<br/>"; }
|
|
|
01-25-2008, 12:48 AM
|
#20 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 265
Thanks: 2
|
PHP Code:
while($total == 1) { ++$x; $total = ((10 * pow($x,3) + 8 * 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)
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
| |