The Little Guy Posted May 20, 2008 Share Posted May 20, 2008 Is there a better way to word this question? The answer is no, since it is an endless loop. Is there an error in this code? <?php $i = 0; while($i < 10){ echo 'Hello<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/ Share on other sites More sharing options...
Daniel0 Posted May 20, 2008 Share Posted May 20, 2008 Whether there is an error or not depends on what the expected behavior is seeing as there is nothing syntactically wrong with the snippet. Sometimes infinite loops are what you want, so they are not per definition errors. However, in this case it would be questionable whether an infinite amount of "Hello"s should be outputted. Furthermore, the usage of the HTML line break tag indicates it's to be on a web server and be served to a web browser. Seeing as the response would never be able to be sent to the client if the code never stops executing one can conclude that, yes, there is an error in the script. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546112 Share on other sites More sharing options...
The Little Guy Posted May 20, 2008 Author Share Posted May 20, 2008 sorry, I meant to write yes, don't know why I wrote no. So, what would be a better way to write the question, or would you leave the question as is? Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546116 Share on other sites More sharing options...
zq29 Posted May 21, 2008 Share Posted May 21, 2008 sorry, I meant to write yes, don't know why I wrote no. So, what would be a better way to write the question, or would you leave the question as is? No, "Is there an error in this code?" is a poor question - I wouldn't waste my time with the thread. A help question should include: What you are trying to make happen What is actually happening The environment it is running on, if appropriate Effort made in expressing the problem A better question would be: I am trying to display 'Hello' ten times on my page, each on a new line but all I am getting is an error message telling me that my script has reached its maximum execution time after about 30 seconds. Could someone point me in the right direction please? Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546308 Share on other sites More sharing options...
Orio Posted May 21, 2008 Share Posted May 21, 2008 A better question would be: I am trying to display 'Hello' ten times on my page, each on a new line but all I am getting is an error message telling me that my script has reached its maximum execution time after about 30 seconds. Could someone point me in the right direction please? As far as I understand, this question is a part of a quiz / test, and not a question asked in some board or for help. So a good question for this piece of code would be: What would the following code produce? And if it's a multi choice question some possible options could be: [*] 10 Times "Hello" each, in a new line [*] An error, because echo has to come with parentheses around it's parameters. [*] Nothing. [*] An internal sever error. etc' Orio. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546346 Share on other sites More sharing options...
zq29 Posted May 21, 2008 Share Posted May 21, 2008 As far as I understand, this question is a part of a quiz / test, and not a question asked in some board or for help.. After re-reading the original post - I think you may be right. My bad. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546400 Share on other sites More sharing options...
The Little Guy Posted May 21, 2008 Author Share Posted May 21, 2008 As far as I understand, this question is a part of a quiz / test, and not a question asked in some board or for help.. After re-reading the original post - I think you may be right. My bad. He is right. I like how you worded it, I didn't run the code, but I would guess yours would be one of two things, either an "Internal server error", or "Nothing" Reasoning: Internal server error - the code would run endlessly, and make the script time out. Nothing - the code would keep running till the time out, and no buffer will be able to push the code to the screen, since the buffer runs when the code has completly finished. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546465 Share on other sites More sharing options...
Orio Posted May 21, 2008 Share Posted May 21, 2008 Yeah, but I guess at some point you'll either get an internal 500 error or as SemiApocalyptic said, you'll get a "maximum execution time" error. You can test it, but either way you have choose the answers wisely so you'll have no doubts about the correct answer. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546472 Share on other sites More sharing options...
AndyB Posted May 21, 2008 Share Posted May 21, 2008 Is there an error in the code? That depends on how you want to interpret 'error'. The 'correct' answer is "no, there is no error". If there is an error, then point out which statement is wrong. The fact (or presumption) that the code will produce no result, an unexpected result, or just crap out is not the outcome of an error. Thinking there is an error derives from our tendency to think that anything that doesn't work 'right' must be wrong. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546489 Share on other sites More sharing options...
The Little Guy Posted May 21, 2008 Author Share Posted May 21, 2008 I would say yes there is an error, but it isn't a syntax error, it is a logical error. If this were to run from command line, then there would be no logical error (if you wanted an infinite loop), or any error at all. So I probably should say in the question something about it being run from the browser. If you would like to take the test (AJAX test JavaScript required): http://phpsnips.com/tests/test.php?level=0 It is only 16 questions, where my current question is last. If you take it, could you let me know about any other misleading questions, or wrong answers. any ways how about this: "What is the problem with this browser outputted code?" A. Nothing B. There is a syntax error C. It is an endless loop D. "hello<br>" must be in parenthesis Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546602 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 E. Short between the keyboard and the floor. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546648 Share on other sites More sharing options...
GingerRobot Posted May 21, 2008 Share Posted May 21, 2008 Question 10 is misleading - is_int() checks a variable's type. Question 11 is misleading, you could leave a loop with exit, you just wouldn't return to the rest of the script. Question 21 is wrong. The answer is true. Firstly you can leave the semi-colon off the last line of your php code. It would also be debatable about what you mean by statement -- you do not need a semi-colon after an if statement. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546799 Share on other sites More sharing options...
The Little Guy Posted May 21, 2008 Author Share Posted May 21, 2008 Question 10: That is what the question asks, how to check for an integer type, at least that is what it is supposed to say. Question 11: As in C or Perl' date=' PHP requires instructions to be terminated with a semicolon at the end of each statement.[/quote'] http://us2.php.net/manual/en/language.basic-syntax.instruction-separation.php Question 21: an if is not statement, it is a construct, but it holds statements and it also contains expressions. http://us2.php.net/manual/en/control-structures.if.php Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546862 Share on other sites More sharing options...
GingerRobot Posted May 21, 2008 Share Posted May 21, 2008 Question 10: The question says "How would you check to see if a value is an integer?" - it does not say how do you check if a variable is an integer. I think there's a difference. And yes, i'm aware i was splitting hairs with question 21. Quote Link to comment https://forums.phpfreaks.com/topic/106532-how-to-word-a-question/#findComment-546891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.