C# Loops

When something needs to happen multiple times in your game/project, it is quite likely that a code loop would be of benefit.

Vincent Taylor
2 min readAug 15, 2021
All the best programmers

FOR:

A For loop will run the code inside the { } braces a certain number of times, based on a changing conditional. The following code inside the brackets will run 5 times.

FOR-EACH:

A For-Each loop, similar to a For loop, runs through the code inside the { } braces a certain number of times, based on a conditional. The following code inside the braces will run 3 times, because the array has a size of 3.

WHILE:

A While loop will repeatedly run the code contained inside the { } braces while the condition is true. The following code inside the brackets will run 5 times.

DO-WHILE:

A Do-While loop acts exactly the same as a While loop, except it is guaranteed to run the code contained inside the { } braces at least once. The following code inside the braces will still run 5 times.

--

--

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.