4.1: while and for Loops - p5.js tutorial

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

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

  • @jimmybuck1993
    @jimmybuck1993 4 года назад +39

    It's not that you're just good at explaining, it's that you're good a at inspiring ideas.

  • @acinaces343
    @acinaces343 4 года назад +12

    I don’t know anyone else who smiles this much while coding

  • @lbruinsl5553
    @lbruinsl5553 29 дней назад

    its been almost 10 yrs since these were made, im watchin in 24/25, and they are great. He is so energetic its easy to watch

  • @cristaldominguez1834
    @cristaldominguez1834 5 лет назад +37

    Omg you are so good at explaining things I’m recommending to anyone who needs these tutorials

    • @ciceroaraujo5183
      @ciceroaraujo5183 4 года назад +3

      And you are really beautiful

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

      @@ciceroaraujo5183 what the Fuck

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

      @@ciceroaraujo5183 no i don't think so

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

      @@ciceroaraujo5183 not my type

    • @TanishFX
      @TanishFX 2 года назад

      @@Aryaman_Agarwal And no one asked you? Find the defintion of a "opinion"

  • @akhilkashyep
    @akhilkashyep 9 лет назад +70

    Hi Daniel! Nice tutorials. Loved your way of presenting them with a smile. Keep it on. Also you keep on asking if any one would watch them...let me tell you I am watching them for last 4+ hours. :)

    • @TheCodingTrain
      @TheCodingTrain  9 лет назад +8

      +Akhil Kashyap oh, i am so glad to hear that thank you!

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

      @@TheCodingTrain i have been watching for about 4 hrs

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

      @@TheCodingTrain after 5 years, i'm still watching these nonstop. You are the greatest teacher!

  • @persenbp4160
    @persenbp4160 4 года назад +5

    you are an incredible and passionate teacher who makes even boring stuffs look really really really interesting !
    i resolved to make this comment every time i watch your vid
    comment 2/x

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

    I've been lost this whole time between for loop and while loop. Thank you for explaining it to us so clearly.

  • @tahaozalozkan5901
    @tahaozalozkan5901 7 лет назад +6

    U're the best teacher i've ever seen. I wish all the best for you from Turkey!!!

  • @AntonioRibeiro-qs3fy
    @AntonioRibeiro-qs3fy 5 лет назад +2

    This guy's teaching style is brilliant and i can totally see why its worthwhile showing us the while loop. It help me understand the concept of for loops so much more clearly..I bookmarked the page and subscribed to the channel...I am officially on the coding train :)

  • @chaios
    @chaios 3 года назад

    Thanks. I have watched a lot of lessons regarding for and while loops, but yours is the most concise and easiest to understand.

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

    Daniel, if everybody else were as clear and understandable as you, our nations might have world peace at last!!!

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

    I respect you 3000 . Best Teacher on the planet!

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

    best programming tutorial ive ever seen!!!!

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

    dude, I LOVE the while loop.
    When the condition in the for loop in not constant, it can lead to really weird errors (array index out of range, etc.)
    while loop is perfect in those cases.

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

    Your videos are really very very helpful. I was lagging in this topic for weeks you cleared it. Appreciated it good work.
    regards from India.

  • @stodsy2783
    @stodsy2783 9 лет назад +8

    Hi Dan, I've thoroughly enjoyed all your videos and my javascript is rapidly improving. Thanks so much for all your efforts and great job sir!

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

    I love your way of explaining, and also the format of your video, very unique and useful for the explanaition

  • @Mo0n1111
    @Mo0n1111 Год назад

    Tahnk you so much for doing these videos, I gave it a shot using the map() funct + for loop. Early days, slow progress but enjoying the train ride!
    function setup() {
    createCanvas(600, 400);
    }
    function draw() {
    noStroke();
    background(220);
    var minCol = color(51,59,53);
    var maxCol = color(137,156,142);

    for (var x = 0; x

  • @mediafilms1169
    @mediafilms1169 9 лет назад +35

    You saving my LIFE... thank you soo much... regards from Germany ;)

  • @FredoCorleone
    @FredoCorleone 6 лет назад +14

    Worth mentioning that there's also a shorthand *++i* . Which differs from *i++* because if you have *++i* in an expression *i* is first incremented and only after evaluated.

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

      Prefix and postfix operator. He probably didn't mention cuz it may just overwhelm beginners.

    • @madsadolfsen406
      @madsadolfsen406 3 года назад

      @@johnyepthomi892 yup

    • @madsadolfsen406
      @madsadolfsen406 3 года назад +3

      @@johnyepthomi892 I'm overwhelmed

  • @fear_less_2020
    @fear_less_2020 2 года назад

    You simplify everything so well. Hats off, Dan! I wanna be a professor too. I am inspired by you a lot!

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

    Thank you for making the content understandable for beginners! You did an amazing job of it.

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

    All great stuff, please keep it coming, learning a lot, thanks

  • @TonyFlexPromo
    @TonyFlexPromo 8 лет назад

    Thank you so much for making these video tutorial. They are absolutly brilliant. After some other online courses and tutors you are the best.

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

    You, are one of the greatest teachers i've ever had!
    The best in the internet so far and the best in coding :)
    Back to learning for me. through you.. to make the world a better place... what? o.O
    -Its nothing.

  • @goldthumb
    @goldthumb 2 года назад

    It's still the last day of 2022 (Toronto). This series is still the best I found for learning JavaScript and p5js.

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

    best teacher in whole world

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

    You are the best professor.

  • @bolddiamond
    @bolddiamond 2 года назад +1

    You're amazing!!! Thank you for sharing this

  • @michaelsakowicz718
    @michaelsakowicz718 2 года назад

    Incredible! You have helped teach for and while in such a simple and wonderful way! Thank you !

  • @walker2683
    @walker2683 6 лет назад +5

    Thank you for helping me. This made me understand loops now thank you

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

    Thank you. You saved me from the volcano of confusion

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

    You are the jesus of p5.js saving everyones life

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

    You are an excellent teacher! Thank you for taking the time. I’ve subscribed and will continue to explore your videos! 🙏

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

    This is insane. Thank you Daniel!

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

    your the best teacher, make me easy to learn :) regards from India

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

    the willpower of this man to not use += or ++ until this video

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

    This was SO helpful! I appreciate your explanations. You made this so much easier to understand! Thank you!

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

    Awesome tutorials! Your teaching method is crystal clear - I've learned a ton over the past couple of days. Thanks for sharing your knowledge.

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

    About 11:25 into the video, line number "17" is highlighted in yellow because the IDE is issuing a warning that the variable "x" has already been declared. To read the actual warning message, just click on the yellow highlighted line number and the text will appear in a little pop-up text box. To correct this warning, remove "var" from within the for loop's argument list, like so:
    for (x = 0; x < width; x = x + 50) {
    You should find that this fix will make the warning go away. I'm sure Dan knows about this, but didn't want to waste time talking about this small detail in order to keep his video short (under 10 minutes).

  • @Muffin--Man
    @Muffin--Man Год назад

    Another great video, here is my code for 13:10
    function setup() {
    createCanvas(400, 400);
    }
    function draw() {
    background(220);
    let x1=20;
    while(x1

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

    Very good explanation. I am th e dumbest guy in coding and you just made me an expert!

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

    you have saved me by allowing me to revise my basics!!

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

    wow,what a nice presentation, all the question i have about loops solved,,,,,keep smiling

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

    awsome! you get me through my programming module :D Really comprehensive

  • @joesteer311
    @joesteer311 8 лет назад

    Dan these videos are great! Love your teaching style, I'm learning a tonne.

  • @安泓仑
    @安泓仑 2 года назад

    谢谢!

  • @frownless
    @frownless 6 лет назад +8

    i wish this guy was my professor in college

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

    Amazing tutorial!! Loved it!!

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

    love your videos man, you're awesome

  • @sweethomes674
    @sweethomes674 Год назад

    Excellent explanations 😊

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

    Thank you so much for this amazing video ! U SAVED MY LIFE !

  • @masonictraveler6558
    @masonictraveler6558 2 года назад

    Amazing teaching!

  • @markus_knoedel
    @markus_knoedel 3 года назад

    Still after some time now this is so helpful.

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

    Waooo teaching style is very impressive

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

    What a wonderful video. Well explained.

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

    'if' transfers to 'while' well. Glad you confirmed that.

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

    I love u r smile and I enjoy your fun learning

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

    GOd bless your life with Grace.
    you are doing best

  • @rituchandra6325
    @rituchandra6325 5 лет назад +5

    no body loves the *do while* loop... XD
    EDIT: your videos are very helpful, i am able to learn new things about programming!! please keep up the good work

  • @emanuel3617
    @emanuel3617 3 года назад

    This... this guy is making me learn and... And I am enjoying it!!! >:0 what is this dark magic that makes me get exited with numbers!?

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

    You will help me pass my exams next month. Thank you sempai -_-

  • @marwa-zr8vk
    @marwa-zr8vk 5 лет назад

    best programming tut

  • @billyzman666
    @billyzman666 3 года назад

    Thank you so much! This is very helpful.

  • @Watchman-Michael
    @Watchman-Michael 6 месяцев назад

    Briliant, thank you. bless you

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

    You did a great job explaining this concept thank you

  • @adambreslin6525
    @adambreslin6525 3 года назад +1

    I was just wondering where the width element came from when you were writing your while loop. I thought you would need to create a variable for that word "width" and assign it a value. Is it apart of the p5.js library, and that's why you can use it? Just need to understand that part. @The Coding Train

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

    dude, you are perfect

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

    Love from Nepal. 🇳🇵

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

    dude, you are hilarious. and excellent, big thank you!

  • @MrSevenEleven
    @MrSevenEleven 9 месяцев назад

    you can center by using "height / 2" for the y value instead of 200, it's better than hardcoding it IMO

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

    If for loops are best practice than why do they teach while loops? Also var is now replaced by let correct? So is let now best practices other than var? Sorry I am new and get confused because classes I’m taking still use var but I hear should be Let now.

  • @shashidhara.g.m655
    @shashidhara.g.m655 5 лет назад +11

    He: someone or no one might be watching this video
    Every 85k viewers : 0-0

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

    so good proffesor

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

    How would use the for loo[p if u wanted to code in a parallelogram by using the "quad" function.

  • @jhuluan-jyun2594
    @jhuluan-jyun2594 6 лет назад

    AWESOME TEACHER!!!

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

    what if the shape has multiple x coordinates like triangle . How will loop will help to get a geometric pattern?

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

    What is the closed caption at 1:03????

  • @lucykim513
    @lucykim513 3 года назад

    he looks so enthusiastic for the boringest shit ever. thanks though this helped quite alot

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

    do u know how to make it come vertically instead of horizontal

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

    question: why does the var x have to be in draw function for code to work? i tried making it global variable but results went eee orw

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

    Hi, why when declare x as a local variable in draw function and we then add 50 the operation happen once and when we declare x as global variable 50 is added to x continuously (x+50=100, 100+50=150, ..... ) so when we run it we got a moving ball.

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

      I know this is a while ago, but the reason this happens is that when you declare it in draw then add 50 to it in draw, it keeps looping. The effect of this means that first x is set to 0 (or the number you started with), then 50 is added to it. Then when the draw function starts again, it resets x to 0, then adds 50 again. This then happens forever.

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

    Why ints in the brackets? Process i get, not sure what ints do though..

  • @krishnakumar-hm9ce
    @krishnakumar-hm9ce 4 года назад

    i think u should join white hat jr
    because i m a white hat jr student and i didnt under stand this for loop in my class but u explain it very well

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

    Hello, Sir... Is there anyway to use break; or continue; to stop looping?

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

    can mouseX and Y be a variables? if so how?

  • @utavtakt9361
    @utavtakt9361 4 месяца назад

    When I add while (x < width) Google chrome crashes? X)

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

    hi!
    I get some error.
    Uncaught ReferenceError: loopProtect is not defined (sketch: line 12)
    can somebody help?

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

    "A 'for loop' consists of three different expressions inside of a parenthesis, all of which are optional. These expressions are used to control the number of times the loop is run. The first expression is a statement that is used to set the initial state for the loop. The second expression is a condition that you would like to check before each loop. If this expression returns false then the loop will exit. The third expression is executed at the end of each loop."

    • @KeyCode98347
      @KeyCode98347 2 года назад

      thanks! that cleared that up for me.

  • @shaksto
    @shaksto 3 года назад

    Hello Mr Daniel, I am having a problem. When I try using the command 'while' the entire tab just lags out. Any tips on what I should do?

  • @singingmermaid4338
    @singingmermaid4338 Год назад

    hey I'm a beginner and a little bit confused what the width means here ( if x < .... ) is with width the width of the canvas meant? or the width of the ellipse? helppppp haha

    • @TheCodingTrain
      @TheCodingTrain  Год назад

      You can come and ask your questions and get help in the discord! It's a little hard to do in RUclips comments: thecodingtrain.com/discord

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

    Why is this not working for me?? It says “Invalid left hand sign in assignment”. I copied your format but it still shows up

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

    Hello,
    Thank you for you videos, I love them! I'd always wanted to learn coding but never knew where to start... now thanks to you and good structured lessons I know =)
    Btw in the end of this video you explain x++. My question is, is there something similar than ++x (like in c++)?

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

    Why in your script, background(0); in Draw() {} don't erase bubbles anytime?

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

      It appears before I draw the bubbles so the bubbles appear on top. For more, ask at discourse.processing.org/! It's a better platform for Processing and p5.js related code questions. You can share code there easily! Feel free to link from here to your post.

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

    Genius

  • @irfankhan-qj4mu
    @irfankhan-qj4mu 5 лет назад

    Love and salute to YOU BY PAKISTAN

  • @alexandermcclure6185
    @alexandermcclure6185 9 месяцев назад

    What about for each?

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

    In the beginning of the lesson I was very confused cause I thought that the draw function went on forever so why does the ellipses with the +1 x only go so many times

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

      Nvm

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

      Ow I have a new issue! In brackets my for loop never works!

  • @sjohn-777
    @sjohn-777 7 лет назад

    Thank you for the classes!
    I've always been kinda lost as to when to use forLoops and whileLoops ? or does it not matter ?

    • @minkihairoil
      @minkihairoil 4 года назад +2

      Yup, it does matter when you use each! For loop are counted loops- they are used for it you want something to repeat a set number of times, and this is specified in the boolean condition in the middle of thr got loop (ex. i < 4).
      While loops however are used after a condition is met. Such as while (!gameOver) {// do this}. They will ONLY RUN if the condition in the while loop is true!
      In summary, for loops are counted loops whereas while loops are conditional loops.

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

    i think while loop is better than for loop because it flexible
    e.g
    while loop that cant be achieved using for loop.
    public static List ShuffleList(List inputList)
    {
    List randomList = new List();
    Random r = new Random(); //using random
    int randomIndex = 0;
    while (inputList.Count > 0)
    {
    // choose between 1 and the MaximumNumberOfQuestions
    randomIndex = r.Next(0, inputList.Count);
    randomList.Add(inputList[randomIndex]);
    inputList.RemoveAt(randomIndex);
    }
    return randomList;