Seasons Greetings

Where we keep all the boring tidbits about the PHPDN site, the news, and what not.

Moderator: General Moderators

User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Seasons Greetings

Post by patrikG »

Code: Select all

while($date<="31 December 2004"){
     if($date<="25 December 2004"){
          echo "Merry Christmas and a";
     }
     echo "happy New Year!";
}
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Nice code patrickG and merry xmas :O)

You forgot to append the date to the $date variable though and will that not display "happy New Year!" everyday before the 25th and 31st?. I never tried it so I am not sure.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

As you're not changing $date your while loop will either do nothing, or run infinitely.

But, err, yeah.. Have a happy non-denominational seasonal period.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

onion2k wrote:As you're not changing $date your while loop will either do nothing, or run infinitely.

But, err, yeah.. Have a happy non-denominational seasonal period.
What exactly do you mean by, "As you're not changing $date your while loop will either do nothing, or run infinitely". Loops are not broken by changing elements, AFAIK???
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

$x=0;
while ($x < 10) {
  echo $x++;
}
What do you think that will do?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

It would blow my HD up.

No really, it would display from 0 - 9
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

$date is set as given. It's a very clever script as it presumes its reader knows the date and knows that $date equals the current date in textual form. Woohaaa, I should have written class, maybe ;)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Joe wrote:No really, it would display from 0 - 9
Exactly. And in patrikG's original code he wasn't changing the value of $date, so either the code wouldn't enter the while block at all, or would enter it but wouldn't ever leave, depending on the initial value of $date.. ergo: "As you're not changing $date your while loop will either do nothing, or run infinitely."
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

WoWWWWWWWWWWWWWWW................ Lets all just say merry christmas and happy new years !
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Phenom wrote:WoWWWWWWWWWWWWWWW................ Lets all just say merry christmas and happy new years !
My thoughts exactly - Merry xmas and a happy new year to all!
kenrbnsn
Forum Newbie
Posts: 13
Joined: Tue Jul 01, 2003 3:34 pm
Location: Hillsborough, NJ USA

Post by kenrbnsn »

So, here's a version that works, no infinate loop, date is set, spacing is correct, etc... :D

Code: Select all

<?
$date = date('j F Y',strtotime('today'));
if($date<="31 December 2004"){
     if($date<="25 December 2004") echo "Merry Christmas and a ";    
     echo "Happy New Year!";}
?>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

onion2k wrote:
Joe wrote:No really, it would display from 0 - 9
Exactly. And in patrikG's original code he wasn't changing the value of $date, so either the code wouldn't enter the while block at all, or would enter it but wouldn't ever leave, depending on the initial value of $date.. ergo: "As you're not changing $date your while loop will either do nothing, or run infinitely."
patrikG wrote:$date is set as given. It's a very clever script as it presumes its reader knows the date and knows that $date equals the current date in textual form.
In short: You can watch the while loop every day, and every day $date will have increased by exactly one. Reason: it's all in our heads

/walks off with a mad giggle, gibbering in a madly hoarse voice: "Alas, the Matrix has revealed itself to me."
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

/walks off with a mad giggle, gibbering in a madly hoarse voice: "Alas, the Matrix has revealed itself to me."
You been eating those expensive cookies you mentioned.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

onion2k wrote:As you're not changing $date your while loop will either do nothing, or run infinitely.
kenrbnsn wrote:So, here's a version that works, no infinate loop, date is set, spacing is correct, etc...
Are you guys serious !?!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

nigma wrote:Are you guys serious !?!
I prefer to call it "passionate". :wink:
Post Reply