https://kotlinlang.org logo
e

elect

01/29/2020, 11:26 AM
while (true) { }
might be simplified to
while { }
1
🤔 1
d

Dominaezzz

01/29/2020, 11:31 AM
There's a YouTrack for this one actually. I'll find a link.
👌 1
e

elect

01/29/2020, 11:34 AM
thanks!
j

jimn

01/30/2020, 2:06 PM
what about repeat{} ?
e

elect

01/30/2020, 2:06 PM
it sounds weird
l

Leon Linhart

01/30/2020, 4:26 PM
while { }
feels wrong because "while" implies that the code is executed while some condition is true which is not the case for an infinite loop. (
for { }
suffers from a similar problem.)
1
e

elect

01/30/2020, 4:29 PM
logically, you should have a point. However given I'm used to read that in C, it feels natural
😓 1
d

Dominaezzz

01/30/2020, 5:09 PM
loop { }
s

stantronic

01/31/2020, 10:32 AM
Copy code
inline fun loop(block: ()->Unit){ 
   while(true) block.invoke()}
1
(except that wont work with break and continue)
j

jimn

01/31/2020, 4:19 PM
this thread is a mirror of the youtrack issue. it seems like the path of minimum resistance is probably something{...} however '...' as an operator is an infinite range semantic. does ... simply alias to Any?..POSITIVE_INFINITY ? will thaat be a follow-up stdlib request to try to reduce gap from maths to source code?
k

Ky Leggiero

03/20/2020, 5:30 PM
@stantronic If you find yourself using
break
and
continue
in a
while (true)
block, you should instead be looking at other, better-fitting patterns. Perhaps the condition that causes you to hit
break
should be in the parentheses instead of
true
, or perhaps you should be using
for
,
filter
,
any
, etc.
2 Views