How can I do a loop like this but in Kotlin way, m...
# getting-started
o
How can I do a loop like this but in Kotlin way, maybe using repeat or some another feature?
Copy code
var isStopped =false

        do {

        }while (isStopped.not())
k
That's fine, maybe put declare the variable inside the loop instead:
Copy code
do {
    var stop= false
    ...
} while (!stop)
o
I stop the process in another place.
k
IN another thread? Then you need be careful and I think you need some synchronization.
o
I use in this way:
Copy code
@Volatile
    var isStopped = false
And use the var in the coroutines:
Copy code
CoroutineScope(Dispatchers.Default).launch {
            do {
                //do my stuff
            } while (movie.isStopped.not())

        }
Is it ok?
k
I think so, yes. You should just use
!
instead of
.not()
though, I've never seen anyone use that.
o
Android Studio suggests this
.not()
but not always. Really, I don't know what is the diffrence, maybe I need to find the dif ) to avoid unexpected issues.
Description is:
Copy code
/**
     * Returns the inverse of this boolean.
     */
k
They're exactly the same, are you sure AS suggests it?
I think it's more intended for function references, eg.
listOf(true, false, true).map(Boolean::not) == listOf(false, true, false)
o
It was 2-3 times the whole time. That's how I know about this operator.
k
In what situation does it suggest it?
o
Unfortunatelly, I don't remember the situation. But it was in the same situation, when I used oposite of some variable with
!
.
I can't reproduce the suggestion in all my case when I use .not() in my project, but I found an option to change
!
to
.not()
though it's not the suggestion. https://prntscr.com/pwulgi
k
Ah right it's also for operator overloading.