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....
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.
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:
Winston Gutkowski wrote:What about:?
No break statement, no flags, and no nasty while() clause.
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.
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
permaculture is giving a gift to your future self. After reading this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton