+ 1
Kotlin 15.2 Practice Range
I get an error "for is not an expression, and only expressions are allowed here". Looked at the solution, tried it again but without effect. Stuck. Help me please :) The code I have used: fun main(args: Array<String>) { var num1 = readLine()!!.toInt() var num2 = readLine()!!.toInt() var sum = 0 for(i in num1..num2){ sum += i } println(sum) }
4 Réponses
+ 5
Put a line break after the for block.
println should start in new line.
Then it will work.
In Kotlin the cost of not using semicolons, is that we have to structure the code more smartly. I'd say it's win-win (for the coder and the compiler).
+ 3
1. Review the lesson before the test. Make sure you use the correct syntax.
2. Copy or link the code you have written. It would be easier to review, than blindly guessing what you did wrong. Rest assured, that the tests work correctly.
+ 2
Hi Tibor, off course. Sorry, not used to this. I have updated my post. Can you please check?
+ 1
@Tibor, thank you very much! :D Did not now this mattered so much, but now do understand the logic behind it. Also this is why no semi-columns are used I suppose. Thanks once again!