OCUP UML fundamental and ITIL foundation
Jesper de Jong wrote:I don't know why anyone would want to write code like that. Can you ask the people who wrote that code why they did this?
Jesper de Jong wrote:You mean like this?
It means that the body of the if-statement is always executed. It's ofcourse unnecessary to write code like that. I don't know why anyone would want to write code like that. Can you ask the people who wrote that code why they did this?
John Quach wrote:I've seen some If statements with a condition that's nothing more than the keyword true....
OCUP UML fundamental and ITIL foundation
John Jai wrote:while(true) is used here to loop till the input is not null. Note that a break statement is used to come out of the loop. Basically the loop condition is checked inside the loop block and not on the while condition expression.
OCUP UML fundamental and ITIL foundation
I earlier wrote: No statements shall follow a while(true) in a block....
Campbell Ritchie wrote:You can set a while loop to read every line, but it is syntax you would never have guessed
Paul Clapham wrote:Or if you still have a religious objection to the break statement, you bring in a flag to salute:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:What about:?
No break statement, no flags, and no nasty while() clause.
Winston
Paul Clapham wrote:You will have noticed that you have duplicate code there. Not the best idea. In this case there's only one line of code to be run before we know whether we have to do the second half of the loop, so it isn't that bad. If you had two lines, you would be having second thoughts about duplicating them, and if you had more than two, you wouldn't do it.
However, yes, I have seen that style before, in fact it's pretty much the standard in RPG code where I work.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:That looks a clumsy way to exit a loop. If you are reading, you can read in a while loop.
You ought to be catching the exceptions from your reader.
You ought to close the reader in a finally block, which you can find if you search this forum.
You can set a while loop to read every line, but it is syntax you would never have guessedIs that straight from the tutorial? I hope you are not paying for it
John Quach wrote:
Yes it is. And no I did not pay for it.Campbell Ritchie wrote:Is that straight from the tutorial? I hope you are not paying for it
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|