Skip to content

Instantly share code, notes, and snippets.

@DevWouter
Created February 15, 2021 07:39
Show Gist options
  • Save DevWouter/1b708dd0d69db4393c83113e262eb531 to your computer and use it in GitHub Desktop.
Save DevWouter/1b708dd0d69db4393c83113e262eb531 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace HideAndSeek
{
class Program
{
static void Main(string[] args)
{
foreach(var s in countDownTo(10)){
Console.WriteLine(s);
}
}
static IEnumerable<string> countDownTo(int startAt, int stopAt=0)
{
int counter = startAt;
while(true)
{
switch(counter)
{
case 2:
yield return "Ready!";
break;
case 1:
yield return "Set!";
break;
case 0:
yield return "Go!";
break;
default:
yield return counter.ToString();
break;
}
counter--;
if(counter < stopAt){
yield break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment