What are Loops? (C# Basics, for, while, do)

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.ย. 2024
  • 🌍 FREE C# Beginner Complete Course! • Learn C# Beginner FREE...
    🔴 Watch my Complete FREE Game Dev Course! 🌍 • Learn Unity Beginner/I...
    📝 C# Basics to Advanced Playlist • C# Basics to Advanced
    🌍 Get my Complete Courses! ✅ unitycodemonke...
    👍 Learn to make awesome games step-by-step from start to finish.
    🎮 Get my Steam Games unitycodemonke...
    ✅ Let's learn all about Loops in C#, they are an integral part of programming that you'll use all the time.
    For, While, Foreach and Do While.
    Learn Unity in 17 MINUTES!
    • Learn Unity in 17 MINU...
    Learn C# BASICS in 10 MINUTES!
    • Learn C# BASICS in 10 ...
    What are Events? (C# Basics)
    • What are Events? (C# B...
    What are Delegates? (C# Basics, Lambda, Action, Func)
    • What are Delegates? (C...
    What are Interfaces? (C# Basics)
    • What are Interfaces? (...
    What are Generics? (C# Basics)
    • What are Generics? (C#...
    What are Loops? (C# Basics, for, while, do)
    • What are Loops? (C# Ba...
    Unity Tips in 10 MINUTES!
    • 12 MORE Unity Tips in ...
    Unity Basics for Beginners
    • Learn Unity in 17 MINU...
    If you have any questions post them in the comments and I'll do my best to answer them.
    🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
    See you next time!
    📍 Support on Patreon / unitycodemonkey
    🤖 Join the Community Discord / discord
    📦 Grab the Game Bundle at unitycodemonke...
    📝 Get the Code Monkey Utilities at unitycodemonke...
    #unitytutorial #unity3d #unity2d
    --------------------------------------------------------------------
    Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
    I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
    You can see my games at www.endlessloopstudios.com
    --------------------------------------------------------------------
    - Website: unitycodemonke...
    - Twitter: / unitycodemonkey
    - Facebook: / unitycodemonkey

ความคิดเห็น • 69

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 ปีที่แล้ว +8

    🌍 FREE C# Beginner Complete Course! th-cam.com/video/pReR6Z9rK-o/w-d-xo.html
    🔴 Watch my Complete FREE Game Dev Course! 🌍 th-cam.com/video/AmGSEH7QcDg/w-d-xo.html
    📝 C# Basics to Advanced Playlist th-cam.com/play/PLzDRvYVwl53t2GGC4rV_AmH7vSvSqjVmz.html
    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Get my Courses @t or my Steam Games 🎮 @t
    Here's another C# Basics video, this time covering on the most important things to know as a programmer, Loops!

  • @alexw9309
    @alexw9309 4 ปีที่แล้ว +64

    Dont use
    for (int i = 0; i < array.lenght; i++)
    Better use
    for (int i = 0, int max=array.lenght; i < max; i++)
    In the 1. the lenght will be calculated on every loop, on the 2. only once. If u have big loops this could make a speed difference.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +10

      Yup, if performance is a concern then caching the length is a nice an easy way to get some ms

    • @GymCritical
      @GymCritical 4 ปีที่แล้ว +3

      This is definitely good for my inventory script which is taking up approx. 0.27ms rn. Scalability wise, this’ll help.

    • @nemesis8508
      @nemesis8508 4 ปีที่แล้ว +4

      Commenting to remember this later

    • @anormalguy8407
      @anormalguy8407 3 ปีที่แล้ว +1

      thanks, this is going into my collection of performant code :D

    • @nexgen.graphics
      @nexgen.graphics 3 ปีที่แล้ว +1

      Makes sense. Thanks for this.!

  • @mephistonight2958
    @mephistonight2958 4 ปีที่แล้ว +9

    You're very quickly become the best Unity channel on TH-cam, you know? No fuss, no messing about... straight in to it covering the important information in a digestible way. Nice one.

  • @JTAGames
    @JTAGames 4 ปีที่แล้ว +5

    This helps tremendously with the project I’m working on right now, thanks!

  • @JG-bb4dc
    @JG-bb4dc 4 ปีที่แล้ว +2

    Thank you Code Monkey. Really appreciate you making this video on the basic C# loops. Looking forward to your next tutorial like this on C#. Keep making these awesome videos on Coding C# with Unity!!!

  • @dhee9040
    @dhee9040 11 หลายเดือนก่อน

    Best vedio on c# loops I've seen everrr

  • @michaelesch
    @michaelesch ปีที่แล้ว

    Thank you so much! I've been struggling with the concept of loops and I think it is starting to click.

  • @ayushsidam289
    @ayushsidam289 ปีที่แล้ว +1

    Finally completed all videos in this playlist 🎉. Thanks for this invaluable playlist sir. 🙌🏻
    But please can you make a video on switch statements. 🙏🏻😇

  • @Andrew90046zero
    @Andrew90046zero 4 ปีที่แล้ว

    I personally have never used the continue keyword, but I bet there are some places where I could use it.
    Also, for anyone else reading. I have heard for loops being called "count controlled loops" in case you hear that term.
    The idea is that while loops are more used for things you are not incrementing repeatedly. And have no solid predefined amount of iterations. So a while loop would be used to hold a simple console program open. Whereas for loops are more for iterating over data structures with a finite size, and therefore, have a known amount of total loops.

  • @jackbamford9749
    @jackbamford9749 4 ปีที่แล้ว

    We need more videos on this series🙌

  • @ThePostalGril
    @ThePostalGril 4 ปีที่แล้ว

    i like your teaching style. i'm learning c# :) i want to make little games. not for profit tho i know someone like me could never make good games but i wanna do it for fun :)

  • @anormalguy8407
    @anormalguy8407 3 ปีที่แล้ว

    I already know how to use these in java but watched anyways and found out that certain syntaxes are different so I guess I still learned some stuff :D

    • @anormalguy8407
      @anormalguy8407 3 ปีที่แล้ว

      also very nice tip on how to remove an object in a list

  • @supertenchoo4271
    @supertenchoo4271 4 ปีที่แล้ว

    my brain is boost with loop...make this basic tutorial it real help us who are new in programming

  • @makinamieclair3769
    @makinamieclair3769 4 ปีที่แล้ว +1

    you can scan list in reverse order to remove element

  • @sagiziv927
    @sagiziv927 4 ปีที่แล้ว

    Important to note that in the for loop you are not forced to write all 3 blocks, you can skip some of them if needed

  • @RawHunterX
    @RawHunterX 4 ปีที่แล้ว +1

    Great vid. Can you do Events in the future?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      I have covered Events here th-cam.com/video/OuZrhykVytg/w-d-xo.html

  • @GaiaTree
    @GaiaTree 4 ปีที่แล้ว +1

    Hi dude. Can u make trade system for mmorpg games? Thanks for helps.

  • @Andrelas11
    @Andrelas11 4 ปีที่แล้ว

    What would be some helpful "game specific" instances you would use each of these loops. I find building on these simple instructions with a practical example helps solidify the information. Many things make sense as a "concept" but implementing the concept is sometimes the most difficult part. Thanks!

    • @andrewshandle
      @andrewshandle 4 ปีที่แล้ว +1

      Looping through a player's inventory, looping through enemies and checking if they are alive (the example CM gives for "Contunue"), looping through visible targets, doing an initiative order in a Turn Based game, updating a status flag on a group of items that are on the ground that is on fire, every system in ECS/DOTS with an Entities.ForEach, etc.
      Basically, any time there can be more than one of something.
      FWIW, whenever CM does these types of pure C# mechanical videos, another one follows it which uses what he is talking about, so I imagine his next video will contain loops.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว +1

      Yeah I normally try to do that but this is such a basic concept I couldn't really come up with a simple example to explain it. Every example I thought about would take longer to explain the example than to show the loops in action.

  • @iUmerFarooq
    @iUmerFarooq 4 ปีที่แล้ว

    I'm waiting for next video please upload as quickly as possible?

  • @svetavasilieva7841
    @svetavasilieva7841 4 ปีที่แล้ว

    Thank you

  • @angelmerchev8933
    @angelmerchev8933 4 ปีที่แล้ว

    im new at programming im using visual studio and unity looks so alike

  • @ArunKumar-xg4st
    @ArunKumar-xg4st 4 ปีที่แล้ว

    Thank you Code Monkey🙂🙂

  • @ighby9828
    @ighby9828 4 ปีที่แล้ว

    I just get an ad of one of your videos... in your video xd

  • @brockormond4131
    @brockormond4131 4 ปีที่แล้ว +8

    Wow, I didn't even know 'continue' was a thing. Embarrassing. I could explain a Recursive loop, but didn't know continue... that's a college education for ya.
    Really, you should do a class for Udemy or something... that'd probably sell well.

  • @manicmillennial3287
    @manicmillennial3287 4 ปีที่แล้ว

    hey CM, ty for this video! What is the "c" after "char" @ 8:27 and what do you mean? I have some trouble hearing you and understanding what you mean by defining "char"

    • @Andrelas11
      @Andrelas11 4 ปีที่แล้ว +1

      The "c" is just a typical name assigned to character variables. You could have named it whatever you wanted. So "c" is the variable name, "char" is the variable type. The variable has no value on its own until you start passing in values from the Array with the foreach loop.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      Yup it's just the variable name, since it's a "char" I just used "c" but it can be any name you want.
      char is a C# type that represents a character. A string is composed of characters.

  • @papadross
    @papadross 3 ปีที่แล้ว

    I'm new to programming and I'm not sure how to ask but I have some code in a for loop that I don't fully grasp.
    for (int i = 0; i < numArray.Length; i++)
    {
    if(Convert.ToInt32(numArray[i])-i != firstArray)
    {
    cons = false;
    break;
    }
    }
    I get what most of this is doing except for the -i behind (numArray[i]). Any info would be most appreciated.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว +1

      I have no idea what numArray and firstArray are meant to represent so I can only tell you what the code is doing
      Convert.ToInt32(numArray[i]) is converting whatever is in numArray[i] into an integer
      Then it's subtracting by 'i' which means it's subtracting more and more and the for loop cycles more and more

    • @papadross
      @papadross 3 ปีที่แล้ว

      @@CodeMonkeyUnity That's what I was wondering. Thanks.

  • @user-yg9rq6xn3o
    @user-yg9rq6xn3o 3 ปีที่แล้ว

    you mean It not runs second time* (not "second loop") at all ? 0_o 13:36

  • @Deadwindshadow
    @Deadwindshadow 4 ปีที่แล้ว

    Whats the difference between while and if statement?
    while (i < 3) {
    do this
    }
    if (i < 3) {
    do this
    }
    I don't see a difference here :/

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      The if code block will only run once and the while code block will run for as long as i is under 3

    • @Deadwindshadow
      @Deadwindshadow 4 ปีที่แล้ว

      @@CodeMonkeyUnity Ah, sure! I was thinking of an if statement in the update function haha, but isee how useful while could be used in not update!
      Thank you!!

  • @David-vz4yk
    @David-vz4yk 4 ปีที่แล้ว

    Could you do tutorials for top down shooter game?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 ปีที่แล้ว

      I've done quite a lot of them and you can see some that I used in the Top Down Shooter game I made unitycodemonkey.com/game.php?g=topdownshooter

    • @David-vz4yk
      @David-vz4yk 4 ปีที่แล้ว

      Code Monkey thanks!

  • @alexw9309
    @alexw9309 4 ปีที่แล้ว

    Does break 2; work in c# for breaking 2 levels or even more? Im from the php world and we have this syntax there. :-)

    • @sagiziv927
      @sagiziv927 4 ปีที่แล้ว

      no, unfortunately you can only break the loop you are in, not the outer loops

    • @alexw9309
      @alexw9309 4 ปีที่แล้ว

      @@sagiziv927 ok, thx for the answer :-)

  • @mr-spoon
    @mr-spoon 4 ปีที่แล้ว +2

    Make video about making amionation

    • @spe.z.artist
      @spe.z.artist 4 ปีที่แล้ว +1

      dai craft make me a sandwich

    • @mr-spoon
      @mr-spoon 4 ปีที่แล้ว

      @@spe.z.artist what about tea?
      Are you writing that while sleeping

    • @spe.z.artist
      @spe.z.artist 4 ปีที่แล้ว +1

      dai craft haha tea would be nice. just thought your comment is a bit demanding. I figured I’d give you a taste of your own medicine. Imagine you work hard to make a video andyou post it and the first comment is “do something else” not even a mention of this video.

  • @dasmaffin1633
    @dasmaffin1633 4 ปีที่แล้ว

    Well if you do i-- in the for loop it is not *infinite* but well yes it will run for a while lol

  • @BigJTT
    @BigJTT 2 ปีที่แล้ว

    It's actually painful you don't use the dark theme xD

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      Sorry but dark theme is painful for me, I can't look at it for more than 30 seconds

    • @BigJTT
      @BigJTT 2 ปีที่แล้ว

      @@CodeMonkeyUnity I feel you probably get that comment alot :D

  • @joseruiz7122
    @joseruiz7122 4 ปีที่แล้ว +1

    Your videos are informative but those fast forwards disorient me. I start to catch on but when you fast forward the steps I'm lost.

  • @developerakhter______0076
    @developerakhter______0076 4 ปีที่แล้ว

    *I found 0.1 Differences in between*
    *C++ && C#*

  • @nullreferenceexception9327
    @nullreferenceexception9327 4 ปีที่แล้ว

    I crashed my pc when i did this lol

  • @BarioIDL
    @BarioIDL ปีที่แล้ว

    if alex watched this 3 years ago, yandere simulator would be finished by now
    (jk you can't cure procrastination)

  • @feliwx4087
    @feliwx4087 4 ปีที่แล้ว +1

    Oofh I'm quick lol

  • @hj1ax
    @hj1ax 4 ปีที่แล้ว

    lol, published 10 seconds ago.