Skip to content

Instantly share code, notes, and snippets.

@LeastFixedPoint
Created August 27, 2012 21:26
Show Gist options
  • Save LeastFixedPoint/3492387 to your computer and use it in GitHub Desktop.
Save LeastFixedPoint/3492387 to your computer and use it in GitHub Desktop.
// Original
void indexOf(int[] haystack, int needle) {
for (int i = 0; i < haystack.length; i++) {
if (haystack[i] == needle) {
return i;
}
}
return -1;
}
// With new construct
void indexOf(int[] haystack, int needle) {
for (int i = 0; i < haystack.length; i++) {
if (haystack[i] == needle) {
break;
}
} then {
return i;
} else {
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment