logic errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

logic errors

Post by p_sha85 »

Hi everyone-

I have the following code and supposedly it contains logic errors. I'm not sure what they are so if someone can help me out with that I will really appreciate it. Thanks!!

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>While Logic</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$Count = 0;
while ($Count > 100) {
$Numbers[] = $Count;
++$Count;
foreach ($Count as $CurNum)
echo "<p>$CurNum</p>";
}
?>
</body>
</html>
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: logic errors

Post by php_east »

this must surely be your homework. i'm not going to help. :mrgreen:
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: logic errors

Post by susrisha »

Code: Select all

 
<?php
$Count = 0;
while ($Count > 100) {
$Numbers[] = $Count;
++$Count;
foreach ($Count as $CurNum)
echo "<p>$CurNum</p>";
}
?>
 
what are you trying to do with this code?? it doesnt output anything
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

Re: logic errors

Post by p_sha85 »

It should fill the array with numbers 1 thru 100 and then print them to the scren. But the code contains several logic flaws that prevent it from running correctly. The problem is, I don't know which are the logic flaws. Hope this clears up the confusion.

Thanks,


*Pooja*
xplore
Forum Newbie
Posts: 16
Joined: Mon Apr 06, 2009 12:06 pm

Re: logic errors

Post by xplore »

p_sha85 wrote:It should fill the array with numbers 1 thru 100 and then print them to the scren. But the code contains several logic flaws that prevent it from running correctly. The problem is, I don't know which are the logic flaws. Hope this clears up the confusion.

Thanks,


*Pooja*
Logic errors and errors are two different things. You are missing an enclosing bracket on one of your loops. As far as logic errors go you're being redundant in 1st initializing an array of nums when you can simply get rid of the array and echo $count ($count being similar to your key values of the array). To me its not a logic error but more so redundant code which logically doesn't make sense to do.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: logic errors

Post by McInfo »

How about "set count to zero; then while count is greater than 100, do something"? That is a logic error.

You are not going to learn anything if you have other people do your homework for you.

Edit: This post was recovered from search engine cache.
Post Reply