Page 1 of 1

logic errors

Posted: Sat Apr 18, 2009 1:00 am
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>

Re: logic errors

Posted: Sat Apr 18, 2009 4:33 am
by php_east
this must surely be your homework. i'm not going to help. :mrgreen:

Re: logic errors

Posted: Sat Apr 18, 2009 5:02 am
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

Re: logic errors

Posted: Sat Apr 18, 2009 12:50 pm
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*

Re: logic errors

Posted: Sat Apr 18, 2009 7:43 pm
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.

Re: logic errors

Posted: Sat Apr 18, 2009 9:53 pm
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.