Learn Swift for Beginners - Ep 5 - Loops Part 1

Поделиться
HTML-код
  • Опубликовано: 27 янв 2025

Комментарии • 64

  • @CodeWithChris
    @CodeWithChris  6 лет назад

    QOTD ⚡Have you learned about loops in another programming language before? Let me know! 👇 Kick start your own app with my free 7 Day App Action Plan ➡️ bit.ly/7dplan

  • @topblogger5234
    @topblogger5234 7 лет назад +1

    i can't believe how easy to understand the basics of swift 3 !!
    thank you very much i really enjoy watching your videos ^^

  • @gabrielraphaelgarciamontoy1269
    @gabrielraphaelgarciamontoy1269 7 лет назад +7

    This series is awesome! I already know C++ and Java, but skimming this video along with Chris' explanations helps me learn the syntax for Swift 3.1 faster. Subbed.

    • @CodeWithChris
      @CodeWithChris  7 лет назад +3

      I appreciate that Gabriel! Thanks for watching with me!

  • @abhishekdadwal5521
    @abhishekdadwal5521 7 лет назад +1

    i really appreciate your comforts man
    i really need this to know how loops work in swift

  • @christopheratkins3988
    @christopheratkins3988 6 лет назад +1

    best swift tutorial hands down! Much love, keep posting brother

    • @CodeWithChris
      @CodeWithChris  6 лет назад

      Thank you for the support!!!!!!!!
      @AdrienVillez

  • @davidlovett880
    @davidlovett880 6 лет назад +11

    I am a 11 year old this taught me to code is amazing.

    • @dagodian5365
      @dagodian5365 6 лет назад +1

      welp i definitely know your not lying about being 11

    • @calebstammen
      @calebstammen 5 лет назад

      @@dagodian5365 ahaha dlajd s;lgasdfjdslghasldfja

  • @litrich8355
    @litrich8355 4 года назад +1

    Hi Chris, I was curious how you would be able to print the results of the for-in statement one by one. A good example I believe would be - when you level up a character its total damage increases by 2 each level. How would we print or insert that data?

    • @CodeWithChris
      @CodeWithChris  4 года назад

      Hello, inside the for loop it will go through the data inside "array" or range of values one by one
      for something like stats you don't need a loop for that, maybe you can just simply access the data and multiply it by a base value (like 2)
      - Francis

  • @viksk4258
    @viksk4258 6 лет назад +1

    awesome chris! You have made it hell easy to understand for newbies ... thanks for the efforts

    • @CodeWithChris
      @CodeWithChris  6 лет назад

      Glad to hear that Vikas, thanks for watching!

  • @hurasane3947
    @hurasane3947 7 лет назад +1

    great series I know java and c# but swift is similar which is cool but how do you control the iterator in the for in loop for example lets say you wanted it to subtract instead of add would you have to put 1...-5?. I have never heard of a for in loop until today. Its amazing how swift knows what your implicit variables are but wont that get confusing as a code base grows maybe its just me and im used to explicity setting variables to types.

  • @8mpgmafia109
    @8mpgmafia109 7 лет назад +2

    Hello at 9:18 how is the print out 15? Thanks in Advance Guys!

    • @CodeWithChris
      @CodeWithChris  7 лет назад +9

      Hey Rubensito, each time it loops, it's adding the next number to the sum. So it's 1 + 2 + 3 + 4 + 5 and then it prints out the total after all the loops.

    • @30guarino
      @30guarino 6 лет назад

      Rubensito Don’t feel bad I had to add the numbers myself

  • @krishanmalhotra7500
    @krishanmalhotra7500 5 лет назад +2

    How do i accept an integer value from the user?
    By the way great teaching methodology

    • @CodeWithChris
      @CodeWithChris  5 лет назад

      Hello, again! I replied on you last comment (which was the first for me in my list of comments)
      @AdrienVillez

  • @trentkelly5369
    @trentkelly5369 7 лет назад +4

    What is the significance of using the word "index"?

    • @CodeWithChris
      @CodeWithChris  7 лет назад +5

      Hey Trent, it's just a variable name and you can specify any name you'd like.
      When you access that variable inside the loop, it gives you the number in your looping range that it is currently on.

    • @MartinJurus
      @MartinJurus 6 лет назад +1

      So if I understand correctly, "for Index..." is the same as when we define variable with var index ?

    •  6 лет назад

      I think it's

  • @joshuachavarria6577
    @joshuachavarria6577 5 лет назад +1

    Hey chris I’m watching this video and when typing in my “sum+= index” i get a pop up that says it cannot concert value of type (unsafe pointer ) could you help me explain why I get this pop up and how I can fix it if it’s not too much of a hassle? Thanks chris love the videos !

    • @CodeWithChris
      @CodeWithChris  5 лет назад

      That's weird, especially with something as basic as an addition. Did you let some space between sum and +. Sometimes sum+ and sum + can mean 2 different things.
      I'm curious to see a screenshot of this, can you post it on our support page? bit.ly/CWCCommunity
      @AdrienVillez

  • @jareek1690
    @jareek1690 7 лет назад +5

    he teaches better than my teacher

  • @vokadekaestheticssalon2425
    @vokadekaestheticssalon2425 6 лет назад +1

    Hey Chris! Can't really understand why you moved the var sum and print("") out of the loop in order for the numbers to add up? Like why does it not work inside the loop?
    THANKS

    • @CodeWithChris
      @CodeWithChris  6 лет назад +2

      Great question! Like mentioned earlier in the video, everything that is written in the loop will "reboot" once the loop run again and all data will be lost.
      If you write a variable outside of the loop, you can use it inside it the loop, save a number in it and let the loop run again without loosing that precious data.
      It's like doing 1 + 2 + 3 + 4 + 5 but always remember the previous count or number while if it was inside the loop, you would do 1 >> erased >> +2 >> erased >> +3 >> erased >> +4 >>.... etc. Like if you were wiping clean a white board after every time you write something down. (Like how my kids behave! Once write something down, the other erase it.... drama!)
      @AdrienVillez

    • @vokadekaestheticssalon2425
      @vokadekaestheticssalon2425 6 лет назад

      @@CodeWithChris Makes so much sense now. Thank you for the fast and easy response!
      All the best

  • @hextaniumfranklin79
    @hextaniumfranklin79 7 лет назад +2

    So, Chris, we talked before yes, but what do the {curly braces} mean?

    • @CodeWithChris
      @CodeWithChris  7 лет назад

      Hello! They're used to "contain" a block of code statements. Most commonly used to contain the code statements for a function or class (Lessons 6-7 of the beginner series).

  • @cris050292
    @cris050292 7 лет назад

    Hi!Thank you very much for this videos,are very helpfull.I just wanna ask you .I saw that you have 2 posts,How to make an app and this one with swift.How I should watch both.In what order,so everything can make sense?
    Thanks again

    • @pineapplepizza4016
      @pineapplepizza4016 7 лет назад

      From my own limited experience, I would say learn the code and syntax first, then learn how to make the app.

    • @30guarino
      @30guarino 6 лет назад

      Exactly what I’m doing now....{
      Know the code
      Print(Soon you’ll be a CODER)
      }👍

  • @zahra7755
    @zahra7755 6 лет назад

    I've been meaning to ask, what's with the
    on the right screen thingy if you 'print' something?

    • @CodeWithChris
      @CodeWithChris  6 лет назад +1

      It's to get a
      return to
      the
      next line
      in the console
      or in a label
      if you do not
      want all the text to be on the same
      line.
      -Adrien

    • @zahra7755
      @zahra7755 6 лет назад

      thanks, lol.

  • @RadenSoCal
    @RadenSoCal 7 лет назад +2

    This is still freaking tough to learn, is there an easier way to understand this? i can repeat this over and over but mayn lol this is a gift but thank you

    • @30guarino
      @30guarino 6 лет назад

      Raden SoCal I felt like I was in Groundhog Day how I kept replaying the 7 minute mark(6times) till I got it lol

  • @nomDePlume999
    @nomDePlume999 6 лет назад

    "immutable value 'index' was never used; consider replacing with '_' or removing it" --- What does that mean?

    • @CodeWithChris
      @CodeWithChris  6 лет назад

      If a variable name is never used, Xcode proposes you to name as underscore.

  • @guyswithhoodie3572
    @guyswithhoodie3572 7 лет назад

    how to print star pattern in swift pro

  • @MartinJurus
    @MartinJurus 6 лет назад

    Great ! I have one question:
    Why is it 15 in the end ? sum is 0 and index is 1 to 5. Then, in the loop, you declare that sum is actualy sum + index, which means 0 + 1 to 5, which is... 5 ? And if we repeat (or loop) that 5 times, we would get 25, no ?
    Little bit confused student

    • @MartinJurus
      @MartinJurus 6 лет назад +1

      Oh okay, i got it. It's actualy 1 + 2 + 3 + 4 + 5 = 15. Still not sure why it just adds up those numbers when we tell it that var sum = 0 + 1 to 5.

    • @acostamanuel2011
      @acostamanuel2011 6 лет назад +1

      if you add
      1 +2 = 3
      3 + 3 = 6
      6+ 4 = 10
      10 + 5 = 15
      you basically add all the numbers together from 1-5 if that makes sense! i was confused also at the beginning.

  • @brucekim5166
    @brucekim5166 5 лет назад +1

    I am 11 and you helped me learn

    • @CodeWithChris
      @CodeWithChris  5 лет назад

      Never too young, never too old! Find your passion and just become amazing at it!
      @AdrienVillez

  • @alanstafford9587
    @alanstafford9587 7 лет назад

    Excellent

  • @Mahadev-x7u
    @Mahadev-x7u 4 года назад

    Thank you....

  • @FewMinuteProgramming
    @FewMinuteProgramming 8 лет назад +1

    Darn, swift looks so interesting. I wish I could develop with it with windows. Guess I got to save up.

    • @heshamghalaab6027
      @heshamghalaab6027 7 лет назад +1

      you can use mac by a Virtual machine "Vmware" on Windows

    • @pineapplepizza4016
      @pineapplepizza4016 7 лет назад +1

      Try a Mac Mini, its the cheapest route if you already have a PC.

    • @quinnnolan7078
      @quinnnolan7078 7 лет назад +2

      Few Minute Programming "buy" a virtual machine. That's what I did to get windows on my mac ;)

    • @vishnusanthosh4594
      @vishnusanthosh4594 7 лет назад +1

      try hackintosh or VMware

  • @sebastian2566
    @sebastian2566 5 лет назад +1

    Only if u wouldve explained what index was, i wouldnt be wondering it for the 11 minutes

    • @CodeWithChris
      @CodeWithChris  5 лет назад +1

      Picture the index to be like the number of floors in an elevator: 0, 1, 2, 3, 4, ....
      Once you are on the second floor, your check for index 2 and you can fetch the data!
      (I like the elevator analogy because index starts at 0, so that's like the main hall before the first floor, easy to make a mistake when you start to count 1, 2, 3, ...)
      Does it make more sense now?
      @AdrienVillez

  • @brucekim5166
    @brucekim5166 5 лет назад +1

    I wanted to be a computer scientist when I grow up

    • @CodeWithChris
      @CodeWithChris  5 лет назад

      Let's go for it! You have all the tools at your disposal to even make apps right now! Don't wait!
      @AdrienVillez

  • @lazyg3n
    @lazyg3n 5 лет назад +1

    Didn’t understood
    Please don’t use such heavy words
    Or if you do please explain it before you use them

    • @CodeWithChris
      @CodeWithChris  5 лет назад

      Thanks for the feedback! This is the more updated version of the Swift for Beginners series bit.ly/LearnSwift2019
      -Kat

  • @zahra7755
    @zahra7755 6 лет назад

    var sum = 0
    sum body once told me the world is gonna roll me,