Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Last active November 29, 2017 10:39
Show Gist options
  • Save luisdeol/6497a7bd682ef2bc789c7c048e6c9d94 to your computer and use it in GitHub Desktop.
Save luisdeol/6497a7bd682ef2bc789c7c048e6c9d94 to your computer and use it in GitHub Desktop.
Using the for statement to iterate across a collection
namespace implement_program_flow
{
class Program
{
static void Main(string[] args)
{
var tasks = new[] {"Analyze", "Design", "Code", "Build", "Test", "Blue screen of death", "Deploy"};
for (var i = 0; i < tasks.Length; i++)
{
var task = tasks[i];
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}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment