6.1: While Loop - Processing Tutorial

  Рет қаралды 217,641

The Coding Train

The Coding Train

Күн бұрын

Пікірлер: 127
@kevnar
@kevnar 6 жыл бұрын
A programmer's wife texted her husband. "While you're out, get milk." ...and she never saw him again.
@potato4687
@potato4687 6 жыл бұрын
well played
@KamariaIsHere
@KamariaIsHere 6 жыл бұрын
🤣🤣
@mariuspet89
@mariuspet89 5 жыл бұрын
Hahaha :))) :))) nice
@GameSteals
@GameSteals 5 жыл бұрын
@@jordanclava931 By that example, husband will always be out, and there will never be milk. Hahahahaha
@itssupremesharma4104
@itssupremesharma4104 5 жыл бұрын
@@GameSteals maybe thats the point Hahaha
@martinds93
@martinds93 7 жыл бұрын
If my college teacher putted just "1 bit" of this excitement to the programming classes, I would be happy. But I'm not, and im watching you. Thank you. Your videos are awesome. Im from argentina.
@kevinch3
@kevinch3 6 жыл бұрын
hey tinchou I feel the same. abrazou
@rawanelabied6654
@rawanelabied6654 4 жыл бұрын
HAHAHAHAHAH
@angelcaru
@angelcaru 3 жыл бұрын
*p u t t e d*
@beatrizlisboasanchez8989
@beatrizlisboasanchez8989 2 жыл бұрын
@@angelcaru He said he is from Argentina, which means English is not his native language 🙄
@angelcaru
@angelcaru 2 жыл бұрын
@@beatrizlisboasanchez8989 Mine isn't either.
@robertomerani
@robertomerani 7 жыл бұрын
Hello everybody. This is my first line of code where a ball bounces from right to left and moves down after reaching the right and left side of the screen. Thank you Daniel Shiffman for your time and patience. I never get tired of watching your videos. float x = 0; float xspeed = 10; float y = 320; float yspeed = 10; float up = 25; void setup () { background (127); size (1280, 640); } void draw () { noStroke (); fill (0); ellipse (x, y, 25, 25); x = x + xspeed; if (x > width || x < 0) { y = y + up; xspeed = xspeed *-1; } while (x < 0) { if (x > width) { y = y + up; } else { x = 0; noStroke (); fill (0); ellipse (x, y, 25, 25); } } }
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
Nice work!!
@gg-lu3lt
@gg-lu3lt 3 жыл бұрын
If someone still confused about 5:37 (why you have to reset x = 10 inside DRAW) and come across this comment I hope the code below can help explaining a bit more (copy and run it in your program.) There beginning of DRAW. until it reach > 400, then it draw the result) won't wrong, but this helped me understand this better. I also hope this could help you guys as well. Happy coding guys :D float x = 0; void setup() { size(400, 300); } void draw() { background(random(255)); while (x < width) { x = x + 1; fill(101); stroke(255); ellipse(x, 150, 16, 16); println("still in WHILE LOOP"); println(x); delay(10); } x = x + 1; println("outside now"); println(x); delay(1000); }
@openopinion4208
@openopinion4208 5 жыл бұрын
i have learned alot from your lectures and still learning.your videos are definitely the best on KZbin and of course amusing.thank you sir for these lectures.
@haleemulhassan9158
@haleemulhassan9158 9 жыл бұрын
@5:37 I really didnt get the part where while loop does NOT draw how we expected, as you mentioned. The first time we go into the while loop, x = 0. Now in the while loop is the command of printing circles using the value of x. So shouldnt it keep drawing circles till the value of x>width within the while loop? Why did you have to put the value of x=0 again before the while loop to see any kind of result. Basically what Im asking is how is the value of x = width on the very second time in the while loop?
@TheCodingTrain
@TheCodingTrain 9 жыл бұрын
+Haleem ul Hassan global variables maintain their value each time through draw. Each loop takes x from 0 to width. So when the loop ends, x equals width. When draw starts over again, x still equals width! So in order for us to see the things drawn again, we have to start x back at zero. It's a very confusing thing b/c the while loop is a loop and also draw() is a loop! This video explains a bit more: kzbin.info/www/bejne/kGnWXmqYmrODZ8U
@haleemulhassan9158
@haleemulhassan9158 9 жыл бұрын
+Daniel Shiffman Ahhh now I got it. The video sure did explain the concept. Thank you :)
@abdulrahmankh1611
@abdulrahmankh1611 2 жыл бұрын
Thats the 2ed Time i understand nothing from my trash Teacher and watch your Videos before my exam instead and it really helps, i am thankful
@popcycleism
@popcycleism 6 жыл бұрын
Where is your school at? Coding with visual breakdown. I understand the concept better! Thank you for this!
@wallaceterra5993
@wallaceterra5993 3 жыл бұрын
I really enjoyed your class! His teaching is fun and very lively! Yes, your video came out perfectly, mistakes happen. Thanks!
@jamesfilosa6277
@jamesfilosa6277 4 жыл бұрын
5:42 - Wouldn't it make more sense to move "background(0);" to setup instead? ...when demonstrating the purpose of the while loop.
@blackchan4249
@blackchan4249 4 жыл бұрын
please continue to ramble on. those bit make the video more interesting. Thank you!!
@abhishekkattimani1302
@abhishekkattimani1302 5 жыл бұрын
My all doubts with loops are get cleared thank you so much sir
@owpeezygaming967
@owpeezygaming967 4 жыл бұрын
way longer than I expected, hehe i rather watch you even for an hour per episode
@reibangchakma
@reibangchakma 4 жыл бұрын
1:26 how did you program that sound?
@stephmacindoe6075
@stephmacindoe6075 3 жыл бұрын
Love the Dora reference, went to see the new film for my 20th birthday
@azrael9986
@azrael9986 5 жыл бұрын
if you watch this at 1.75x or 2x speed it's beautiful, it's lovely, this is an example.
@kushbhogate6263
@kushbhogate6263 4 жыл бұрын
better watch at 0.25 x speed
@Maha_s1999
@Maha_s1999 2 жыл бұрын
You are so likeable as a teacher!!! I love your style! Just starting CS50 and although not quite there with the coding language part (I assume this is C?) I feel this will be useful later 🙂
@achievementcell4631
@achievementcell4631 6 жыл бұрын
I love this man.
@chaiyakheourn9970
@chaiyakheourn9970 8 жыл бұрын
I love your teaching so much!
@ruchisheth9430
@ruchisheth9430 5 жыл бұрын
At 5:04, when we are putting ellipse inside the while loop, the first time draw is executed, while function is executed with x being 0, it reaches width n stops but why ain't those circles seen? The second time draw has x =width so while will not execute but first time while function inside draw executes perfectly so why can't we see circles?
@ruchisheth9430
@ruchisheth9430 5 жыл бұрын
Just realized background is the culprit
@hoaang4759
@hoaang4759 5 жыл бұрын
Ok
@brystet6642
@brystet6642 5 жыл бұрын
I will never stop
@raphaelmorgan2307
@raphaelmorgan2307 4 жыл бұрын
"I guess at this point just email if you have a question" the KZbin comments: am I a joke to you?
@ramachhetri5368
@ramachhetri5368 4 жыл бұрын
Him: Maybe you will, also conquer the universe or something. Thanos: I would have done that if the avengers didn't stop me!
@DruishQueen
@DruishQueen 5 жыл бұрын
Hi! Why do you use "eclipse" instead of "circle" for the circle shape? Sorry if you went over this and I missed it!
@fredericomendonca4572
@fredericomendonca4572 5 жыл бұрын
It's ellipsenot eclipse! And an ellipse might not be a circle
@DruishQueen
@DruishQueen 5 жыл бұрын
Frederico Mendonça oh yeah I meant ellipse haha.
@jacobwojcik9888
@jacobwojcik9888 4 жыл бұрын
I am having an issue with the starting bit of the video with the if statement. If we only run the block of code when x is less than 16 (the width of the ellipse), then wouldn't we get to the point where x = 16? And when evaluated against width (also with the value of 16) we get a false evaluation where we do not run the block of code, and then simply run the ellipse command with x = 16 over and over again. So, from this perspective the eventual coordinate for the ellipse would be (x = 16, y = 150). My expectations were to see the ellipse at that coordinate over and over because 16 (x) is never less than 16 (width), and so you would never update the value because you never run that line of code due to the evaluation being false. Of course, this perspective is wrong, because we clearly get an output that eventually ends with the ellipse coordinate of (x = 400, y = 150). Sorry for the long winded question, but I just can't seem to reason it through on my own. Any clarity would be greatly appreciated. Happy coding!
@celiacasimiro465
@celiacasimiro465 4 жыл бұрын
9:15 Oh My! I have watched Dora The Explorer, before.
@parastoon3706
@parastoon3706 6 жыл бұрын
I had a really hard time digesting the "while" loop and still don't quite understand one thing. Why does it matter to reset x=0? I mean if you put "x=0;" before the While loop, shouldn't it be useless? pulling my hair out here...
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Would you mind asking 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.
@mikejones-vd3fg
@mikejones-vd3fg 6 жыл бұрын
take the background out of the draw function and you'll see it draws all the circles without having to reset it to x = 0;
@elliotsefaradi4568
@elliotsefaradi4568 3 жыл бұрын
can you do that particle system with the while loop?
@xuefangzheng6454
@xuefangzheng6454 5 жыл бұрын
Hi, I don't understand what makes it different when u add x = 0; before the while loop at the beginning of this video. It has already declared x and given it a value on the top of the code.
@TheCodingTrain
@TheCodingTrain 5 жыл бұрын
Would you mind asking 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.
@andreacoricciati4909
@andreacoricciati4909 4 жыл бұрын
What if I wanna make it go to left once I reach mouseX > 300?? I tried with x = x -1 with an if statement that says if(mouseX > 300 && mouseX < width){x = x-1} but it creates another loop once I reach 300 , it doesn't go "turn" the loop fo the left.
@MiksCasal
@MiksCasal 3 жыл бұрын
Conquer the Universe. Yes. :D
@cyberguide_in
@cyberguide_in 8 жыл бұрын
Hi Daniel, I did not understand why did you declare x = 0 again if you had already done that earlier in the beginning float x = 0; ?
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+BABLU KUMAR Since draw() is repeating over and over again I need x to be reset back to 0 each time. The global "float x = 0;" could actually be removed here and only declare x in draw().
@cyberguide_in
@cyberguide_in 8 жыл бұрын
Thanks a lot. Well, I sent you a mail as well a few days back. Maybe you forgot to reply.
@theaeleonore4359
@theaeleonore4359 5 жыл бұрын
okay yeah I understand that, but how do I get rid of the previously drawn ellipse with the while loop?
@aangel-s2p
@aangel-s2p 3 жыл бұрын
nest background in the loop so it draws new background every loop
@rishoo6976
@rishoo6976 6 жыл бұрын
instead of doing x = x + 1, couldn't you do x++ or x+= 1?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
indeed!
@jusaggoldcow1125
@jusaggoldcow1125 7 жыл бұрын
u R getting good at the back and forth thing dan! lol
@mlittleprogramming780
@mlittleprogramming780 4 жыл бұрын
Great video!
@valbrownsmith5656
@valbrownsmith5656 2 жыл бұрын
Since draw is already a loop, can't you use that loop instead of a while loop?
@debanjanaghosh6634
@debanjanaghosh6634 4 жыл бұрын
Writing int x=0 as global does nothing. local int x=0 in draw() makes the program run. Why? Please help
@ryanharris4066
@ryanharris4066 5 жыл бұрын
Why mouseX actualizes with the "if"?
@TheRealHedgehogSonic
@TheRealHedgehogSonic 5 жыл бұрын
Whenever I try to make a while loop in the draw() method of my programs, the window crashes. Can anyone tell me why?
@SuperMan-pd3kg
@SuperMan-pd3kg 6 жыл бұрын
thank you mate you were a great help
@tehnay4817
@tehnay4817 7 жыл бұрын
Instead of adding "fo"r statement inside "while", i just put "x=x+mouseX+1;" and got the same solution, i dont know should i, but i am just a little proud of myself for, making code smaller, by myself.
@Elxuekos
@Elxuekos 9 жыл бұрын
take your time and dont worry, hopefully we'll get better explanations
@georgikocharyan3305
@georgikocharyan3305 7 жыл бұрын
Hey, can I ask a question? If I change mouseX to mouseX / 5 as to create less of a space between circles, it works as intended, until mouseX drops under 3 (checked with println). Why? I can't really find out, I've tried a lot of things but it crashes as soon as your mouse dips left.
@georgikocharyan3305
@georgikocharyan3305 7 жыл бұрын
nvm, solved it! Processing lops off the comma, so as soon as mouseX / 5 reaches 0. something, you get 0!
@post_hit_invincibility9940
@post_hit_invincibility9940 7 жыл бұрын
Noob Question. When x is definded as 0 over and over again, this should mean that x = x+10 always definses x as 10, or? I do not get the logic here. Any Help? :)
@puphuc9415
@puphuc9415 7 жыл бұрын
x is definded as 0 over and over again, because he use background on draw(), so when the first time draw() finish, the result will be like we expect but because background on draw() and the x still = width so while() not work and screen still balck . So he must put x = 0 to each time draw{} execute to while() do its job. I am not native english speaker so i have some problem with this help. forgive me if you don't understand my answer because my poor in english
@gauravbanwari1981
@gauravbanwari1981 6 жыл бұрын
if the background is in void draw(),then why dont we see the ellipse moving ? Instead there are multiple copies.
@ivanlin7995
@ivanlin7995 6 жыл бұрын
because the while loop is place after the background(), when draw() begin, it sets the background first and draw all the ellipse then run draw() function again. draw -> set background -> draw ellipse -> draw -> ......
@jaredlester5628
@jaredlester5628 5 жыл бұрын
What is the value of width?
@f_u_n_e_r_a_l
@f_u_n_e_r_a_l 7 жыл бұрын
Dan I miss to see all this great content, get well soon :)
@s.peanutbuterson6733
@s.peanutbuterson6733 7 жыл бұрын
what happened?
@oorschot5626
@oorschot5626 3 жыл бұрын
I don't really get what happens when you reset X back to 0 every time through draw.. ?
@RobberDoDoro
@RobberDoDoro 8 жыл бұрын
How to make the code of the bubble falling down? (the begin of this video one) thank you~
@timeslongpast
@timeslongpast 8 жыл бұрын
Copy this into your code :D if(circleY > height || circleY
@SpyrodoZ
@SpyrodoZ 6 жыл бұрын
can someone tell me whats wrong whit this code? void setup(){ size(500,500); } void draw(){ background(255,0,0); x = 0; { while( x < width) x = x +1; ellipse(x,250,50,50); } }
@rohanj96
@rohanj96 6 жыл бұрын
you didn't write float x; in the top of the code. so the pc couldn't understand what x was. That's what I think the problem is
@---xp7yw
@---xp7yw 6 жыл бұрын
it is because you didn't initialized the x.
@usmanlatif4985
@usmanlatif4985 4 жыл бұрын
hmmm.. copied and pasted this yet I get the following error "Script error. (: line 0)"
@Quidoute
@Quidoute 3 жыл бұрын
int thanks = 0; while(thanks < infinite) { println("THANKS and i hope i did no mistake"); }
@宋文鹏-v6f
@宋文鹏-v6f 8 жыл бұрын
hey i have a question Why the video does not end?
@hectorgarlinga2899
@hectorgarlinga2899 9 жыл бұрын
the draw function contains a for loop?
@hectorgarlinga2899
@hectorgarlinga2899 9 жыл бұрын
+Daniel Shiffman thank you for your explanation, just saw the video "6-4A Loop Inside Draw" where you explain just that . i am amazed all the things you can do with processing, seems a very powerful tool.
@Calz20Videos
@Calz20Videos 7 жыл бұрын
I added a y... kinda could work as a coordinate plane.
@Majestic12zombies
@Majestic12zombies 4 жыл бұрын
i dont get this code to work, when i move background to setup it works but yours is in draw and it keeps working, im in python's module and my code is the one below: x = 20 def setup(): size(600, 600) #background(0) def draw(): background(0) global x while x < width: fill(255) noStroke() ellipse(x, 20, 20, 20) x = x + 20 if someone knows it would be very useful, thanks :(:
@Majestic12zombies
@Majestic12zombies 4 жыл бұрын
nevermind, for some reason the variable x should have been below draw function not above setup, i dont know why but it worked :)
@nenasaniatadaoaten5818
@nenasaniatadaoaten5818 3 жыл бұрын
what if num1 = 3; num2 = 2; (num1 > num2) is this true ?
@johnnycincocero
@johnnycincocero 8 жыл бұрын
How can I turn these sketches into .gifs?
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Johnny CincoCero I would take a look at saveFrame() which allows you save a sequence of images that you could stitch together into a GIF. processing.org/reference/saveFrame_.html
@johnnycincocero
@johnnycincocero 8 жыл бұрын
Thanks, Sir.
@Hydr312
@Hydr312 7 жыл бұрын
what is with the "do" loop ? how this work
@Smellycheecksyt
@Smellycheecksyt 4 жыл бұрын
I’m moving too fast 💨 😂
@angelcaru
@angelcaru 3 жыл бұрын
The difference is that the code in do...while(...) loops always executes at least once. For instance, while(false) {...} would never run, but do {...}while(false) would.
@7cmhg840
@7cmhg840 6 жыл бұрын
Why is the subtitle in Portugese? Are you Portugese?
@made2youtv336
@made2youtv336 5 жыл бұрын
want more video bout this plzzz
@kevinch3
@kevinch3 6 жыл бұрын
Thank you smiley guy. When I can I will subscribe you
@artistalreem1180
@artistalreem1180 6 жыл бұрын
Write a C++ programme that reads a sequence of integers terminated by zero value then finds the percentage of the negative numbers and the percentage of the positive number in the sequence. The programme output is as shown: : Enter a sequence of in integers terminated by zero 6 -7 -8 10 -12 14 15 2 -6 the percentage of negative numbers is 44.4 the percentage of positive numbers is 55.6
@dr__ey
@dr__ey 3 жыл бұрын
OMG I SCREAMED OUT LOUD WHEN I GOT 0 for mouseX omg
@farazk9729
@farazk9729 3 жыл бұрын
Conquer the universe! Hahahaha!
@luisnannini
@luisnannini 8 жыл бұрын
deadmau5 - while(1
@caleblonggrear2796
@caleblonggrear2796 5 жыл бұрын
/‘sjjkkkkkkkkmna kno n in
@angelcaru
@angelcaru 3 жыл бұрын
while(true);
@sidhuz633
@sidhuz633 5 жыл бұрын
just ad x = x + mouseX + 1; there you go
@sidhuz633
@sidhuz633 5 жыл бұрын
but add if condition is best because we need x = x + 1 for once only when mouseX
@rabeaahsan2070
@rabeaahsan2070 6 жыл бұрын
cool
@ZoyaKhan-we8zi
@ZoyaKhan-we8zi 7 жыл бұрын
i need c compiler
@techgaming1125
@techgaming1125 5 жыл бұрын
Uh-huh!
@RealDTSM
@RealDTSM 5 жыл бұрын
anyone here watching as a programming student? like if you are(not leeching likes i promise)
@hoaang4759
@hoaang4759 5 жыл бұрын
Ok
@altaccount8392
@altaccount8392 2 жыл бұрын
Bruh said ok
@mccallumc
@mccallumc 7 жыл бұрын
Zero!
@khuzairimohamad
@khuzairimohamad 2 жыл бұрын
whos from mmu? raise ur hand
6.2: Two Loops / Grid Exercise - Processing Tutorial
2:56
The Coding Train
Рет қаралды 122 М.
Coding Challenge 180: Falling Sand
23:00
The Coding Train
Рет қаралды 1 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 15 МЛН
4.1: Variables - Processing Tutorial
19:02
The Coding Train
Рет қаралды 197 М.
While Loops | C++ | Tutorial 20
8:26
Giraffe Academy
Рет қаралды 14 М.
Coding Challenge 181: Weighted Voronoi Stippling
28:59
The Coding Train
Рет қаралды 179 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,2 МЛН
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 674 М.
6.3: For Loop - Processing Tutorial
7:00
The Coding Train
Рет қаралды 220 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 303 М.