ME FIRST GAMES
Menu

games for me and you

C# - 4 Powerful Loops

9/8/2020

1 Comment

 
Picture
A loop statement allows YOU to execute a group of statements multiple times.
💪They are very powerful, especially if you need to execute a task N times or iterate over many objects.

⭐️ foreach loop
📌 Executes a block of statements for each instance in an array, list, or any IEnumerable.
👍 You'll see this loop often, using it to perform the same task for multiple objects.

⭐️ for loop
📌 This loop allows you to initialize variables and change them after each iteration until a condition is false.
👍 Use this if you need to keep track of the current index in an array.
👍 Good if you just need to iterate over any numbers.

⭐️ while loop
📌 Simply executes a block of statements until a condition is false. The condition is checked before the first iteration.
👍 Good for running tasks until some state has changed.
👍 e.g. Move player until they are dead. Eat food until full.

⭐️ do while
📌 Similar to the while loop, however, the condition is checked after the first iteration.
👍 Use this when you have a task you always want to run before the loop condition.
👍 e.g. Player enters input, if the input is not valid then try again, else exit the loop.

⭐️ Loops are both fun and powerful tools at your disposal.
⭐️ You may struggle with learning loops, that's ok. Things will click after hours of practice.
⭐️ If you find yourself repeating the writing them the same code over and over, consider a loop.

➡️ Follow @mefirstgames for more game dev tips.⠀
➡️ Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html⠀ 

1 Comment
Jery link
2/6/2021 03:04:45 am

Niice blog you have

Reply



Leave a Reply.

    Picture
    Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
    GAMES HERE

    Red Matter

    Star Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.

    Archives

    April 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2019
    March 2019
    December 2018
    April 2018

    Categories

    All

    RSS Feed

Copyright (c) 2020 Me First LLC
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments