How does this loop work?

Revision en2, by Raythroughspace, 2021-03-26 05:12:15

How does this loop work in C++? Is there an equivalent while loop?

int firstTrue(int lo, int hi, function<bool(int)> f) {
	for (hi ++; lo < hi; ) {
		int mid = lo+(hi-lo)/2;
		if f(mid) hi = mid;
		else lo = mid+1;
	}
	return lo;
}
Tags #c++, for loop

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Raythroughspace 2021-03-26 05:12:15 147
en1 English Raythroughspace 2021-03-26 04:42:19 142 Initial revision (published)