java - Are these two code snippets the same or do they differ in any way? -


i working on implementing union find problem encountered snippet.

while (root != id[root])         root = id[root]; 

isn't same

while ((root = id[root]) != id[root]); 

except may second construct executes assignment operation @ least once while first construct may not execute once if initial condition false. there other differences?

they different, think of order in executed.

in first check whether root != id[root] , then assign root = id[root].

in second first assign (nested) , then check.

the usual idiom bufferedreader:

string line; while((line=bufferedreader.readline()) != null) { } 

if change first method:

string line; while(line != null) {      line=bufferedreader.readline() } 

we won't enter while loop...


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -