Why this (stream) is not possible in Kotlin , also...
# announcements
c
Why this (stream) is not possible in Kotlin , also why do we have different syntax for
for-loop
https://pastebin.com/K1uQx2mL
sophia.likedPeople.stream().forEach(x->println(x.name))
g
why do we have different syntax for 
for-loop
different comparing to what?
sophia.likedPeople.stream().forEach(x->println(x.name))
This is incorrect Kotlin syntax, it’s not how lambda syntax works in Kotlin you need:
stream().forEach { x -> println(x.name) }
or even: stream().forEach { println(it.name) }
c
different comparing to what?
Java , my bad for not pointing that out.
g
So what is your question? What kind for loop do you want? Kotlin for loop is the same as java for each loop, but with type inference and keyword
in
instead of colon
c
I miss the typical Imperative for loop.
g
Do you mean initialization/condition/change for loop? Kotlin intentionally doesn’t support it (so it’s not syntax changed, C-style for loop is just not a part of language, only foreach loop is supported), it has bad readability and also requires mutable variable which makes it even more error prone (Kotlin tends to use immutable everywhere where it’s possible) Do you have particular example where you need 3-part for loop?
c
I'm using Kotlin for Competitive programming atm (just for change from Java) and certain problems involves loop which i'm comfy with traditional for-loop.
Kotlin have for-loop for only iterables it seems.
g
you still have while and do/while loop
indeed for competitive programming you probably should check some other approach, usually
while
+
break
works for it
f
imperative for loop with ranges in kotlin
Copy code
for (i in 1..5) {
        println(i)
    }
also: https://try.kotlinlang.org/#/Examples/Basic%20syntax%20walk-through/Use%20a%20for-loop/Use%20a%20for-loop.kt
c
It doesn't make it Imperative.An Imperative often have fine grained control. having conditions , increment/initialization.
But for-loop in kotlin way 🙂