Skip to content

Instantly share code, notes, and snippets.

@WillSullivan
Created December 12, 2017 15:24
Show Gist options
  • Save WillSullivan/38ccfedb1f4c655c6f1b01cf73c343af to your computer and use it in GitHub Desktop.
Save WillSullivan/38ccfedb1f4c655c6f1b01cf73c343af to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HowDoILoops
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int maxLoop = 5;
for(; i < maxLoop; i++)
;
Console.WriteLine($"The reason why i is {i} is because we increment i every loop (that's the i++ bit), each time checking it against maxloop.");
Console.WriteLine("We keep doing that until i is equal to or greater than maxloop (that's the i < maxloop bit");
Console.WriteLine($"Putting it together, you must realize that i will be {i} when the loop completes.");
Console.WriteLine("If it wasn't, our loop would never end. We can't have that, now, can we?");
Console.WriteLine($"So that's why i is {i}. Press any key if you understand.");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment