On 02-10-2012 11:59, Bálint Horváth wrote:
The problem was already solved. I forgot to send a copy to the list...

Rodrigo, break!? Ohh man, it's a crazy idea... A developer DOES NOT use
break at all (in a loop)... (switch is an exception)

I personally find this statement to be utter bullshit. There is nothing wrong with using break. There is a very good reason why it's available in the language. In very many cases, it costs a lot less code to add a break than to add additional clauses to your while-conditional.

You don't honestly believe that:
while(list($key,$user) = each(file('someUserList')) and $foundUser=false) {
   if($user == $usernameWeAreLookingFor) {
      $foundUser = true;
   }
}

looks oh so much better than a simple:

foreach(file('someUserList') as $key=>$val) {
   if($user == $usernameWeAreLookingFor) {
      break;
   }
}

Also do note that it is very hard to use your "do not use break, ever" when you want to use foreach and want to stop at the first find.

Seriously, stop giving advice to never use perfectly good code.

In very complicated, long, loops, I agree that using break in various places can make debugging difficult. The solution however is not to refrain from ever using break, but rather to change your code into a clearer format. This is like saying "you can make bombs from fertilizer, ergo fertilizer should not ever be used!". Everything has its use, and abuse. Same goes for goto, it can also be used for good.

In the other hand Thomas, you should use while and count the lines and u
need to test if username found...

Ehr, he could also use foreach, for or any other loop construct...

On a sidenote: please, please, please do not say "u need". There is no "u" in english, it's written (and pronounced) "you". Stick to that, you sound like a damned dumb teenager to me when using such needlessly abbreviated words.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to