BREAK

  • Comments posted to this topic are about the item BREAK

  • Heh... the correct answer is @j. 😛

    Great question, BTW.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Nice question, thanks Steve.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Jeff Moden (3/4/2015)


    Heh... the correct answer is @j. 😛

    Great question, BTW.

    + 1 😀

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • Curious as to why the Break doesn't exit from the IF , as the referenced BOL page suggests that it should ? ( It clearly does work as stated, just not sure what the BOL reference to the IF ...ELSE statement refers to ? )

    Exits the innermost loop in a WHILE statement or an IF…ELSE statement inside a WHILE loop. Any statements appearing after the END keyword, marking the end of the loop, are executed. BREAK is frequently, but not always, started by an IF test.

  • I gave the correct answer, but I am confused as well when I read BOL after that 🙂

  • I know it's in SQL, but it reminds me of an intro to programming class in school years ago. I still remember that approach, no matter how hard I try to forget.

  • archie flockhart (3/4/2015)


    Curious as to why the Break doesn't exit from the IF , as the referenced BOL page suggests that it should ? ( It clearly does work as stated, just not sure what the BOL reference to the IF ...ELSE statement refers to ? )

    Exits the innermost loop in a WHILE statement or an IF…ELSE statement inside a WHILE loop. Any statements appearing after the END keyword, marking the end of the loop, are executed. BREAK is frequently, but not always, started by an IF test.

    That's some pretty bad grammar, although technically it can be parsed to be correct.

    First note that it says "innermost loop" not "innermost block". So it won't exit an IF statement, because that's not a loop.

    Then "in a WHILE statement or an IF…ELSE statement inside a WHILE loop" indicates where a BREAK can be located, not what it acts upon.

  • This is the first time the explanation confused me more than the question. 🙂 Thanks for the clarification, sknox!

    Nice one, Steve.

  • archie flockhart (3/4/2015)


    Curious as to why the Break doesn't exit from the IF , as the referenced BOL page suggests that it should ? ( It clearly does work as stated, just not sure what the BOL reference to the IF ...ELSE statement refers to ? )

    Exits the innermost loop in a WHILE statement or an IF…ELSE statement inside a WHILE loop. Any statements appearing after the END keyword, marking the end of the loop, are executed. BREAK is frequently, but not always, started by an IF test.

    I inferred the exact same thing from the MSDN site https://msdn.microsoft.com/en-us/library/ms181271.aspx. Why even mention the IF...ELSE statement if it's always going to exit the loop anyway?


    [font="Tahoma"]Personal blog relating fishing to database administration:[/font]

    [font="Comic Sans MS"]https://davegugg.wordpress.com[/url]/[/font]

  • The explanation of sknox makes sense, at least given the empirical evidence from running the code. Still, the documentation does seem decidedly poor in that it takes almost legalistic reasoning to discern the actual behavior from it.

  • archie flockhart (3/4/2015)


    Curious as to why the Break doesn't exit from the IF , as the referenced BOL page suggests that it should ? ( It clearly does work as stated, just not sure what the BOL reference to the IF ...ELSE statement refers to ? )

    Exits the innermost loop in a WHILE statement or an IF…ELSE statement inside a WHILE loop. Any statements appearing after the END keyword, marking the end of the loop, are executed. BREAK is frequently, but not always, started by an IF test.

    That fooled me as well. What it actually does makes more sense, but the above section from BOL makes it sound like it's going to break out of the IF statement.

  • david.gugg (3/4/2015)


    archie flockhart (3/4/2015)


    Curious as to why the Break doesn't exit from the IF , as the referenced BOL page suggests that it should ? ( It clearly does work as stated, just not sure what the BOL reference to the IF ...ELSE statement refers to ? )

    Exits the innermost loop in a WHILE statement or an IF…ELSE statement inside a WHILE loop. Any statements appearing after the END keyword, marking the end of the loop, are executed. BREAK is frequently, but not always, started by an IF test.

    I inferred the exact same thing from the MSDN site https://msdn.microsoft.com/en-us/library/ms181271.aspx. Why even mention the IF...ELSE statement if it's always going to exit the loop anyway?

    Good question.

  • It broke out farther back than I thought it would.

  • Scored 1 point. Thanks for the quick brain teaser, Steve!

    Thanks.

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply