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.

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Vincent Taylor

153 Followers

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