 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
01-20-2008, 12:33 AM
|
#1 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
01-20-2008, 12:37 AM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
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: 309
Thanks: 44
|
lol, thanks
__________________
no signature set
|
|
|
|
01-20-2008, 12:43 AM
|
#4 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
01-20-2008, 12:55 AM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
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: 309
Thanks: 44
|
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)
__________________
no signature set
|
|
|
|
01-20-2008, 01:00 AM
|
#7 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
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: 309
Thanks: 44
|
Quote:
Originally Posted by xenon
Right...sorry for taking away your enthusiasm then...my bad 
|
none taken, i just got bored lol
__________________
no signature set
|
|
|
|
01-21-2008, 09:45 AM
|
#9 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
02-24-2008, 03:32 PM
|
#10 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Posts: 32
Thanks: 5
|
Quote:
Originally Posted by sketchMedia
how about (my personal fav, recursive infinate loops):
...
or even
PHP Code:
for (;;)
{
echo 'lollll';
}
|
Oh, the "For ever" Loop :)
I read about it in the past week :)
__________________
מטבחים (hebrew)
|
|
|
01-21-2008, 12:02 PM
|
#11 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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
|
#12 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
01-21-2008, 01:54 PM
|
#13 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 264
Thanks: 2
|
Infinite loops are bad I crashed my computer thrice because I could not find the loop -.-
|
|
|
|
01-21-2008, 04:00 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
01-21-2008, 05:21 PM
|
#15 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Brilliant thread, I must say. :P
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-22-2008, 10:26 PM
|
#16 (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
|
#17 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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
|
#18 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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)
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-24-2008, 04:54 PM
|
#19 (permalink)
|
|
The Wanderer
Join Date: Oct 2007
Posts: 20
Thanks: 0
|
PHP Code:
<?php while(1) print 'lol'; ?>
|
|
|
|
01-24-2008, 09:51 PM
|
#20 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
haha, yet another popular treath by me.
Invisible Loop
for(;;) { echo "<br/>"; }
__________________
no signature set
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|