2

i'm reading a blog that give something php coding tips.there are two places I don't understand.

  1. less/not use continue.

  2. the structure :

    do{
      if(true) {
           break;
      }
      if(true) {
           break;
      }
    } while(false);
    

    is better than :

    if(true) {
    } else if(true) {
    } else {
    }
    

can somebody explain why ?

steve
  • 608
  • 1
  • 5
  • 16
  • The if block isn't even necessary. – Cole Tobin Jun 09 '12 at 03:56
  • Does it pertain to how PHP handles the `if` and `do`? Write a readable code... PHP should perform the right optimizations to make no difference between the two structures - if it does not, it should/will. A link to the tips? – Déjà vu Jun 09 '12 at 04:37
  • 1
    Any optimization tips like these should be ignored. I'm sorry you wasted your time reading that blog. – Matthew Jun 09 '12 at 04:53
  • Regarding question 2: see http://stackoverflow.com/questions/1445025/what-is-the-advantage-of-a-do-whilefalse . It's got nothing to do with PHP specifically, it's just a pseudo-pattern. – DCoder Jun 09 '12 at 05:15

2 Answers2

0

I highly doubt this as a do { } while () is checked every iteration, whereas an if is just a simple comparison.

Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
0

Maybe the point they were trying to demonstrate in the blog is that a do {} while() loop will pause your code until a condition is met, where as the if statements will be parsed and your code will continue regardless of whether the condition is met or not.

Michael Whinfrey
  • 573
  • 4
  • 14