Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parsing and operating on a value iteratively
public static int[] ParseIteratively(string data)
{
var results = new List<int>();
var sum = 0;
foreach (var cmd in data)
{
switch (cmd)
{
case 'i':
sum++;
break;
case 'd':
sum--;
break;
case 's':
sum = sum * sum;
break;
case 'o':
results.Add(sum);
break;
}
}
return results.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.