Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Last active November 29, 2017 10:39
Show Gist options
  • Select an option

  • Save luisdeol/09650e96069434969a0855fe6f5c28e1 to your computer and use it in GitHub Desktop.

Select an option

Save luisdeol/09650e96069434969a0855fe6f5c28e1 to your computer and use it in GitHub Desktop.
Use the foreach statement to iterate across a colection
namespace implement_program_flow
{
class Program
{
static void Main(string[] args)
{
var tasks = new[] { "Analyze", "Design", "Code", "Build", "Test", "Blue screen of death", "Deploy" };
foreach (var task in tasks)
{
if (task == "Test")
{
Console.WriteLine("Test? Nah, I'm going to skip this... ");
continue;
}
if (task == "Blue screen of death")
{
Console.WriteLine("Well, I forgot to push my changes to Git...");
break;
}
Console.WriteLine($"Task: {task}");
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment