Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqlexpress database file auto-creation error, dbf2mysql parameter, WWWXXXAPC, wwwxxxAPC, How to unsubscrube from dategen spam, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO

Links

XODOX
Impressum

#1: loop inside a loop

Posted on 2008-04-18 03:51:02 by Alan Willsher

------=_Part_2017_18851270.1208483462092
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi can you put a loop inside a loop?

what I want to do is have something looping every 1 second and then
something else looping once every 10 seconds.

something like a combination of these two..

$x = 0;
while ($x < 1000) {
echo "1";
$x++;
sleep(1);
}

$y = 0;
while ($y < 100) {
echo "2";
$y++;
sleep(10);
}

but at the same time so it would output something like

1111111111211111111112111111111121111111112

Thanks

------=_Part_2017_18851270.1208483462092--

Report this message

#2: Re: loop inside a loop

Posted on 2008-04-18 04:02:27 by Trevor Gryffyn

Yup.. you can do that. Easiest way to find out is to give it a try :)

As long as your loop conditions don't conflict or you do stuff to change
variables in a counter-productive way (ie. breaking your logic) then you
should be ok.

-TG

----- Original Message -----
From: "Alan Willsher" <al.willsher@googlemail.com>
To: php-general@lists.php.net
Date: Fri, 18 Apr 2008 02:51:02 +0100
Subject: [PHP] loop inside a loop

> Hi can you put a loop inside a loop?
>
> what I want to do is have something looping every 1 second and then
> something else looping once every 10 seconds.
>
> something like a combination of these two..
>
> $x = 0;
> while ($x < 1000) {
> echo "1";
> $x++;
> sleep(1);
> }
>
> $y = 0;
> while ($y < 100) {
> echo "2";
> $y++;
> sleep(10);
> }
>
> but at the same time so it would output something like
>
> 1111111111211111111112111111111121111111112
>
> Thanks
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#3: Re: loop inside a loop

Posted on 2008-04-18 05:03:51 by Casey Chu

On Thu, Apr 17, 2008 at 6:51 PM, Alan Willsher
<al.willsher@googlemail.com> wrote:
> Hi can you put a loop inside a loop?
>
> what I want to do is have something looping every 1 second and then
> something else looping once every 10 seconds.
>
> something like a combination of these two..
>
> $x = 0;
> while ($x < 1000) {
> echo "1";
> $x++;
> sleep(1);
> }
>
> $y = 0;
> while ($y < 100) {
> echo "2";
> $y++;
> sleep(10);
> }
>
> but at the same time so it would output something like
>
> 1111111111211111111112111111111121111111112
>
> Thanks
>
<?php
$x = 0;
while ($x < 1000) {
echo "1";
$x++;
if ($x % 10 == 9)
echo "2";
sleep(1);
}
?>
:)
--
-Casey

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#4: Re: loop inside a loop

Posted on 2008-04-18 16:51:19 by Alan Willsher

------=_Part_3872_4859315.1208530279271
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Thanks !

On Fri, Apr 18, 2008 at 4:03 AM, Casey <heavyccasey@gmail.com> wrote:

> On Thu, Apr 17, 2008 at 6:51 PM, Alan Willsher
> <al.willsher@googlemail.com> wrote:
> > Hi can you put a loop inside a loop?
> >
> > what I want to do is have something looping every 1 second and then
> > something else looping once every 10 seconds.
> >
> > something like a combination of these two..
> >
> > $x = 0;
> > while ($x < 1000) {
> > echo "1";
> > $x++;
> > sleep(1);
> > }
> >
> > $y = 0;
> > while ($y < 100) {
> > echo "2";
> > $y++;
> > sleep(10);
> > }
> >
> > but at the same time so it would output something like
> >
> > 1111111111211111111112111111111121111111112
> >
> > Thanks
> >
> <?php
> $x = 0;
> while ($x < 1000) {
> echo "1";
> $x++;
> if ($x % 10 == 9)
> echo "2";
> sleep(1);
> }
> ?>
> :)
> --
> -Casey
>

------=_Part_3872_4859315.1208530279271--

Report this message