I'm currently reading a code and i found a method starting like this :
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
}
Can someone explain me the condition while ? That a = b != c seems weird to me.
Seems like your eyes are glancing over a pair of parentheses:
while ( (userInput = stdIn.readLine() ) != null) {
}
I've attempted to make it more clear above.
The variable userInput
is being assigned stdIn.readLine()
. And while userInput
isn't null following that assignment, the loop continues.
It's just a one-liner for handling the userInput
update, as well as checking for null