Kotlin Questions. | SoloLearn: Learn to code for FREE!

+3

Kotlin Questions.

is there any way I can do the assignment like this in println statement in kotlin? https://code.sololearn.com/cOi2wXxYvnJa/?ref=app

6/17/2018 4:39:30 PM

Tanay

7 Answers

New Answer

+12

Kotlin does not allow this option. But you can do it the following way (definitely is not clean as in Java): https://code.sololearn.com/cY4JZAzhppI8/?ref=app

+3

hinanawi yes, in this case I can assign before printing there is no harm but if have condition like this : while (fetching some data and != null ) something=fetch data again; insted of that if I write something like this : while(save fatched data to var != null) something = assign saved data then it can significantly reduce fetching time because it will fetch data only once.

+3

I have just started learning kotlin today so didn't even reached till loop so just asking if I can write the experience like this in while loop or not.

+3

When I do something like that, I do it this way: var data = fetch() while (data != null) { process(data) data = fetch() }

+2

I mean it should assign 22 to f before printing it.....can I write this kind of expression in println.

+1

which assignment are you talking about?

+1

Tanay afraid it can't do that. not to knowledgeable about kotlin, but as it seems from the errors, a statement cannot be put inside a print statement. you can just put "f = 22f" in the line before, don't see anything wrong with that