Created
August 27, 2012 21:26
-
-
Save LeastFixedPoint/3492387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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