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>
logic errors
Moderator: General Moderators
Re: logic errors
this must surely be your homework. i'm not going to help. 
Re: logic errors
Code: Select all
<?php
$Count = 0;
while ($Count > 100) {
$Numbers[] = $Count;
++$Count;
foreach ($Count as $CurNum)
echo "<p>$CurNum</p>";
}
?>
Re: logic errors
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*
Thanks,
*Pooja*
Re: logic errors
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.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*
Re: logic errors
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.
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.