Jump to content

How to write this


cmb

Recommended Posts

What's the problem?

 

me too!

 

there is no 'correct way'.  either the logic works, or it doesn't.  Looks to me, you want $c to be gt 5 and lte 9 to continue the loop....

 

coupla things, style wise:

 

make compound conditionals consistent.  if (cond1 && cond2 && cond3), condX should be consistent. 5<$var and $var>5 are logically the same, so cond1, cond2, cond3 should be the same format...  this is piddling, but good practice, hence:

 

while ( 5 < $c && $c <= 9) is better written as while ($c>5 && $c<=9)...

 

this is piddlin, along the same lines, but perhaps more useful.

 

with conditional loops, make the condition ASAP, as in KISS.  Actually works well for all conditionals...

 

I want to find all female canucks of legal age, who can driveget me to the border.

 

if ($sex == f && $nationality = can && $age>21 && issset($driver_id) && $hasGPS)

 

logically may work, but is horrible to figure out, throw in some () and/or, and gets messy fast....

 

whereas:

 

while($notFound) OR while($found) OR while(~$found) is lightly more elegant in a human way, or not.  just passing logic to var value, syntactically makes conditional loops easier to deal with.

 

oops, imho

 

$foobar = //var to test

$good = new array(6,7,8,9);

while(in_array($foobar, $good))

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.