Last active
December 16, 2020 22:38
-
-
Save JohnMGant/406103d589a46f68711ec9c07fe8edb6 to your computer and use it in GitHub Desktop.
Adds an array of integers using goto (don't do this!)
This file contains hidden or 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
| internal class GotoAdder : IIntegerAdder | |
| { | |
| public int Add(int[] values) | |
| { | |
| int sum = 0; | |
| int count = values.Length; | |
| int index = 0; | |
| BEGIN: | |
| if (index == count) goto RETURN; | |
| int value = values[index++]; | |
| sum += value; | |
| goto BEGIN; | |
| RETURN: | |
| return sum; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment