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
Post a Comment