I have seen in many of open source codes the do-while(0). Can anybody let me know when this is useful and whats the significance of constructing such code?
The do-while construct is useful when you want to run something at least once, and in this case, only once, because the while( 0 ) will end the do-while.
It's true they can be sloppy, that isn't to say they're always sloppy. Often times they are very practical.
kooth wrote:
The do-while construct is useful when you want to run something at least once, and in this case, only once, because the while( 0 ) will end the do-while.
The thing is, if you want something to run once and only once, you don't need any loop at all. Which is why the do{}while(0); construct is kind of ridiculous.