Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #191 Check if any value in a list is larger than a limit

Given a one-dimensional array a, check if any value is larger than x, and execute the procedure f if that is the case

import "slices"
if slices.ContainsFunc(a, func(i int) bool {
	return i > x
}) {
	f()
}
for _, v := range a {
	if v > x {
		f()
		break
	}
}
unsigned i;
for (i = 0; i < sizeof(a) / sizeof(a[0]); ++i) {
	if (a[i] > x) {
		f();
		break;
	}
}

New implementation...
< >
tkoenig