Loops in C++ (for loops, while loops)

  Рет қаралды 396,461

The Cherno

The Cherno

7 жыл бұрын

Twitter ► / thecherno
Instagram ► / thecherno
Patreon ► / thecherno
Series Playlist ► • C++
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/CYUQ
MAIN Lens ► geni.us/ZM3CmG
Microphone ► geni.us/wqO6g7K
Slack ► slack.thecherno.com
Stream ► / thecherno
Website ► www.thecherno.com
Facebook ► / thecherno

Пікірлер: 275
@ignacior.dealmeida8581
@ignacior.dealmeida8581 3 жыл бұрын
When your professor from one of the best universities in the US sends you to a video from the Cherno to explain a CS principle :')
@soccerz222
@soccerz222 3 жыл бұрын
@byu
@1stplace362
@1stplace362 3 жыл бұрын
wait what?? which college is that
@ezshroom
@ezshroom 3 жыл бұрын
@@1stplace362 That must be the best university ever. Or the best teacher, don't know.
@dackerdaw5208
@dackerdaw5208 3 жыл бұрын
That's way better tho, why waste your time explaining basic stuff that anyone could learn in 15 min by just testing or reading the docs or watch videos like this. Instead, you can teach your student stuff like problem-solving and using these tools to do something meaningful. In Uni, you should learn how to solve a problem, not how to use c++.
@tate_talks354
@tate_talks354 2 жыл бұрын
Fr
@Zorrr
@Zorrr 2 жыл бұрын
For C++20 users, with the std::ranges & views library you can also use std::iota to iterate a certain bounds, eg: for(const auto& value : std::views::iota(0, 100)) std::cout
@gykg3202
@gykg3202 3 жыл бұрын
Learn more in 12 minutes than in a 80 minute lecture with my professor
@anungoob6450
@anungoob6450 2 жыл бұрын
Samee 🤦‍♀️🤦‍♀️
@guy-
@guy- Жыл бұрын
That's the beauty in good teachers on KZfaq
@cweasegaming2692
@cweasegaming2692 11 ай бұрын
I keep seeing people saying this. Y'all are wasting your god damn money lmao
@sytnoff1
@sytnoff1 3 ай бұрын
yah man they will do anything except teaching easily
@ETXAlienRobot201
@ETXAlienRobot201 6 жыл бұрын
"game done, i rendered my one frame, we're done here" XD
@NeoKailthas
@NeoKailthas 3 жыл бұрын
well, you have a lot going for you with this game. it supports all platforms with almost all hardware configurations. it loads quickly. it is better than Cyberpunk. it has replay value. it levels the playing fields with speed runners. etc....
@slavsquatsuperstar
@slavsquatsuperstar 3 жыл бұрын
Bethesda: hold my beer
@suntzu1409
@suntzu1409 3 жыл бұрын
@@slavsquatsuperstar CDPR: ( ͡° ͜ʖ ͡°)
@suntzu1409
@suntzu1409 3 жыл бұрын
@@NeoKailthas most importantly its not pay to win
@The_Original_ZacBarton
@The_Original_ZacBarton 3 жыл бұрын
EA be like
@168grhp
@168grhp 6 жыл бұрын
excellent video! perfect amount of detail and moves at a good pace.
@alexandercourtney1075
@alexandercourtney1075 2 жыл бұрын
Thank you so much! This is my first week of coding and this video really helped solidify my new knowledge. Definitely gonna check out your other videos
@BossBeneBaby
@BossBeneBaby 3 жыл бұрын
for each loops are also very nice even tho they are also just a fancy for loop. Anyway i just like the syntactic sugar and the legibility "do this for every element of this list/array". I just rewatch this whole series in 2021and I still love it.
@crashfactory
@crashfactory Жыл бұрын
+1. once i realised that c++ had a "For each" loop, i was over the moon, and really made me think about c++ in a different light. i thought the "for each" was reserved for "higher level" languages like python. not so! For those interested, it's for (int x : arr) { //use x in code here. arr is array of int type. change int to the type contained in the array. }
@groverkennedy2049
@groverkennedy2049 6 жыл бұрын
thanks man! I got sick and I missed 2 days of class and for and while loops were discussed and of course I had to miss it so when I came back I was confused af.
@h0lybehgeZuZ
@h0lybehgeZuZ 4 жыл бұрын
I have noticed that when writing programs that ask the user to input whether or not they want to run the program again, do-while loops are perfect for this because you always run the program at least once, but at the end, you can check the condition of whether the user wants to run the program again, and if it’s false, you don’t, or if it’s true, then the program repeats. You can do the same thing in for or while loops, but the advantage is that the compiler doesn’t need to check the condition for the first run of the loop in the do-while loop, whereas in for and while loops, you do. Very minor optimization, but it all adds up in the end. Great vid by the way.
@Manimanocas
@Manimanocas 2 жыл бұрын
Ty i was using while loops and this is a much better alternative
@aarushiagarwal8938
@aarushiagarwal8938 2 жыл бұрын
after watching this video I felt no need to watch another you have a nice talent to explain anything in just a simple way😊😊😊😀😀 this video is really helpful and informative
@jeremygong4190
@jeremygong4190 2 жыл бұрын
that for loop tricks are not only just beautiful, but it does also bring me the openings of viewing codes in a much bigger picture. I very carefully watched, practiced, and took notes of every single vid in your watchlist so far. And in my perspective, and in my mother tongue: “自从看了你的片子,现在我程序写得越来越浪了。。。” 🤣🤣🤣🤣😂
@SrbijaaBree
@SrbijaaBree 4 жыл бұрын
For loops in depth with disassembly? We're waiting for it! :D
@suntzu1409
@suntzu1409 3 жыл бұрын
Yeah very much
@syednouman2067
@syednouman2067 2 жыл бұрын
This is explained so well, thanks man
@figorachman
@figorachman 3 жыл бұрын
Thank you, what an excellent explanation!
@deeplodh6353
@deeplodh6353 Жыл бұрын
bro u are amaizing i was not undrstanding loop explained in my school. this was giving me a hard time. but u saved the day. thanks for explaining things this good .
@user-gs2vw1uy5v
@user-gs2vw1uy5v 3 жыл бұрын
this is the best video in youtube explains loops, KEEP GOING DUDE
@user-gs2vw1uy5v
@user-gs2vw1uy5v 3 жыл бұрын
+ ITS THE SHORTEST ONE!
@unsalad
@unsalad Жыл бұрын
Really loving this tutorial as it generates interest, Thanks Cherno
@notdeeq
@notdeeq 2 жыл бұрын
Thank you sir love you every much for saving my day with this tutorial keep up the excellent work! 😃
@loryon
@loryon 7 жыл бұрын
Very well explained. Awesome video as usual :)
@ReginaldoTrindadeXXI
@ReginaldoTrindadeXXI 3 жыл бұрын
The best video series I ever had seen! Thanks From Brasil!
@peiquedq
@peiquedq 7 жыл бұрын
Great as always :)
@universebug5423
@universebug5423 5 жыл бұрын
Bröther, may I have some Lööps?
@Markus_included
@Markus_included 5 жыл бұрын
Brøther, where äre my Løøps
@17reason
@17reason 3 жыл бұрын
Lööplar nerde lan Cafer!
@nope2660
@nope2660 3 жыл бұрын
eqsene hırrıme lööpne defakardo!!!
@leixun
@leixun 4 жыл бұрын
*My takeaways:* 1. for loop vs while loop 8:25 2. do while loop 10:00
@mouhou9795
@mouhou9795 5 жыл бұрын
ah thanks dude my teacher failed to explain what the order of the for loop actually was
@ZeroaccessMusic
@ZeroaccessMusic 6 жыл бұрын
Can you make a video about best coding practices you would commonly see at big companies or what style most programmers use that would be great
@dennissabene1938
@dennissabene1938 3 жыл бұрын
As there are tons of conventions across all programming languages there really isn’t a defined “industry standard” Coding style and standards differ between companies according to their specific company policies. Larger companies tend to employ software configuration management teams that ensure process and tools are used in the manner that the business has defined. Hope this helps.
@dennissabene1938
@dennissabene1938 3 жыл бұрын
Shah Bhuiyan arrogant know it all? I didn’t realize that being honest as an engineer was being arrogant... better look in the mirror and reconsider how easily you’re offended by honesty. It’s called professional courtesy not arrogance. 👍🏼
@Dannnneh
@Dannnneh 3 жыл бұрын
@Shah Bhuiyan Are you for real?
@violetsnow5546
@violetsnow5546 3 жыл бұрын
@Shah Bhuiyan tf, he gave a reasonable answer.. so aggressive man.
@dennissabene1938
@dennissabene1938 3 жыл бұрын
The point I was trying to make is that you can’t prepare for the industry because you don’t know the standards of the company you may be hired at. Best thing to do is present yourself as a professional that is eager to work and excited to learn something everyday.
@lbsna3232
@lbsna3232 6 жыл бұрын
Thanks you for this best speaking and it is very easy to understand.
@nanthilrodriguez
@nanthilrodriguez 6 жыл бұрын
@TheChernoProject could you do a video on the performance differences between recursion and actual loops? I'm interested in how can I determine what general conditions exist where recursion would be slower than looping in C++?
@websurfer5283
@websurfer5283 6 жыл бұрын
Great series!!
@mohamedatef91994
@mohamedatef91994 6 жыл бұрын
I want to know the difference between them in memory ?
@gijimbo1337
@gijimbo1337 3 жыл бұрын
So I feel like there's a slight difference between the while and for loops in the scope of the iterator variable. - The for loop creates the iterator variable at start (scoped to the for loop) and then frees/deletes it when done (out of scope). - The while loop requires a variable that's scoped at least one level above the loop so it doesn't get freed up when the whole loop is over. Am I wrong in this?
@nathanherder1414
@nathanherder1414 5 жыл бұрын
Whoa that's a cool lamp shade
@HBWT
@HBWT 2 ай бұрын
Thank you! Now I comprehended loops in c++ better!
@murloc_rampage3856
@murloc_rampage3856 9 ай бұрын
There's also the matter of time when choosing between for and while loops. While loops take more time to be completed in many languages so in code that might need to iterate millions of times, it is best to use for loops because of the sheer speed the code can execute as well as the Big O scale.
@pradyumnkejriwal3007
@pradyumnkejriwal3007 7 жыл бұрын
Very good vid cherno! 😘
@makov2299
@makov2299 2 жыл бұрын
when this guy is teaching better than the professors in my university in Bulgaria. Awesome video dude. You are amazing. Thank you!
@jackthake7209
@jackthake7209 6 жыл бұрын
later on in the series can you cover unit testing?
@TheJoshuamcgowan
@TheJoshuamcgowan 2 жыл бұрын
super helpful explanation. cheers bru
@CalvinMaighan
@CalvinMaighan 3 жыл бұрын
Wow so glad I'm following this tutorial instead of the Standford one I almost selected
@fanisdeli
@fanisdeli 7 жыл бұрын
are you still working on android support for Sparky Engine?
@kitara_69
@kitara_69 Жыл бұрын
Thank you!
@vanshitdiwaker5077
@vanshitdiwaker5077 6 жыл бұрын
Thanks alot bro!!!!
@rass2498
@rass2498 4 жыл бұрын
exactly what i was searching fr
@sembaeff
@sembaeff 5 жыл бұрын
Perfect!
@bryce8793
@bryce8793 5 жыл бұрын
awesome vid cheers
@lesterjohn583
@lesterjohn583 5 жыл бұрын
Thanks for the vid I learned a lot from it. Can you make a video on how to get the average of integers between x and y where x and y are user inputs? Loving your videos. Lots of love from the Philippines!
@lloydclintonenyia9221
@lloydclintonenyia9221 2 жыл бұрын
Thanks alot. It was well depicted.
@Ferocious_Imbecile
@Ferocious_Imbecile 2 жыл бұрын
Always the best explanations. what is normally about as pleasurable as pulling teeth is actually fun here.
@cocoarecords
@cocoarecords 5 жыл бұрын
best explanation out there
@bryansenanin7249
@bryansenanin7249 4 жыл бұрын
oh i know what is looping now thanks pretty hard for me even just a basic program im new from programming currently studying 2019 hehehe
@zamanraja9531
@zamanraja9531 2 жыл бұрын
some sick guy!!! i understood this better than my lectuer explaining it which some sh*** powerpoint slides. Lifesaver!!
@krish-ut9de
@krish-ut9de 2 жыл бұрын
Thank you a lot.
@xvengence5239
@xvengence5239 3 жыл бұрын
you are the best dude
@7.59-fmclosed7
@7.59-fmclosed7 3 жыл бұрын
I just realized when rewatching this that instead of doing while(true) { Function(); } to call a function an infinite amount of times (could be useful for game loops and etc) you could also do for( ; ; function()) which looks a bit neater in my opinion
@cancetin2652
@cancetin2652 3 жыл бұрын
Thank you
@beluga3211
@beluga3211 2 жыл бұрын
This video help me a lot in understanding this concept thanks a lot btw watching in 2021
@blackfun4448
@blackfun4448 3 жыл бұрын
best cpp tutorial ever!
@USELESSFACTSDAILYDAY
@USELESSFACTSDAILYDAY Жыл бұрын
Finally someone who actually explained both for loop and while loops I was having problems understanding for 1 month I couldn't understand this guy made it so easy to explain it so well now I finally understand it 😁 thank you so much sub like ++
@user-pz5dz4mo8x
@user-pz5dz4mo8x 2 жыл бұрын
2021 is here, still works
@jensknaack2593
@jensknaack2593 4 жыл бұрын
I think the usage of i, j ... as loop-variables comes from the past: In Fortran variables with names starting I, J, K, L, M and N are integer variables.
@sengetomakama7072
@sengetomakama7072 2 жыл бұрын
Thanks for this video broo... can you please do more on nested loops
@lesptitsoiseaux
@lesptitsoiseaux 3 жыл бұрын
My son is 12 and we are learning c++ thanks to you! My son is interested in robotics and machine vision. Is opencv up your alley?
@pierrebleile2457
@pierrebleile2457 5 жыл бұрын
Playing with this, I found that the "i" variable declared in the for statement goes out of scope when the for loop exits. It's worth mentioning. Also, does the for loop declared "i" variable have a performance advantage over one created before the loop? (ie is it a register variable, not stack variable?)
@drwisdom1
@drwisdom1 4 жыл бұрын
I have been programming in C and C++ since 1982. The only change in the language standard that caused my code to fail to compile and forced me to make changes to my code base was when they changed the scope of variables declared in for loops. Used to be variables declared in for loops were outside of the loop scope, but they changed it so those variables were inside loop scope (which is really the correct way when you think about it). I always declared my loop variables in the for loop so if I had two successive loops using the same variable i, then the second loop could no longer see i and I had to declare i above the first for loop rather than within. I still declare my variables inside for loops except when the previous occurs.
@_MK81
@_MK81 2 жыл бұрын
The Cherno: for loops are actually really, really flexible. Python: hold my beer.
@prochchhannomahmad8298
@prochchhannomahmad8298 3 жыл бұрын
thanks
@AbdulMoiz-ho8rx
@AbdulMoiz-ho8rx 2 жыл бұрын
excellent
@20thCB
@20thCB 4 жыл бұрын
Really should have talked about range-based for loops eg for (int n : numbers) as they are extremely common since C++11.
@hameedahmadzai9768
@hameedahmadzai9768 8 ай бұрын
Thanks bro,
@rezamehrzad5128
@rezamehrzad5128 3 жыл бұрын
Feburary 2021? Still the GOAT.
@pranav9339
@pranav9339 Жыл бұрын
The whisky in the background table looks delicious. Good job tho.
@samunemeth
@samunemeth 3 жыл бұрын
I is used because you can think of a for loop like the x-axis of a coordinate system. which is represented with I.
@samnewman7321
@samnewman7321 7 жыл бұрын
I'm curious, there was no mention of range based for loops, perhaps that would have required too much additional discussion about the related data structures 😬
@jamesmnguyen
@jamesmnguyen 7 жыл бұрын
Sam Newman They're the same thing as a regular for loop. Just syntax sugar. But if he were to go into them he would have to explain iterators.
@samnewman7321
@samnewman7321 7 жыл бұрын
James Nguyen yeah that was kind of what I eluded to. I guess from my perspective I primarily write JavaScript (nodejs) and since the addition of `for of` loops to the language it has been my goto, but this is an easier sell, despite it also being built on the principle of iterators. It's not quite the same as directly iterating over memory allocation though 😊
@stellarestuary589
@stellarestuary589 6 жыл бұрын
Thank you so much for explaining do while loops, I finally understand them now.
@elhamajmotgir2470
@elhamajmotgir2470 6 жыл бұрын
i looped this video
@coalyboi7939
@coalyboi7939 5 жыл бұрын
ayy
@pierrefiore6933
@pierrefiore6933 Жыл бұрын
Sequence, Condition, Iteration. The fundamental building blocks of code. Without Iteration, there is no need to have code. Most programmers fail on Sequence....the order of when to do what.
@kretoskim8555
@kretoskim8555 6 жыл бұрын
Very helpful thanks..though I didn't get the "while loop" good...great thanks though
@zakiali8518
@zakiali8518 4 ай бұрын
Your background music is awesome! Where do you pull them from?
@georgecristianiordan3712
@georgecristianiordan3712 5 жыл бұрын
Finally one explanation that i can f**king understand, sorry for swearing but man, you explained and made me understand what others couldn`t with only one example. You are the master, thank you!!!
@Laevatei1nn
@Laevatei1nn 3 жыл бұрын
Why did you swear then sorry?you can just not swear you know
@xXtrollplayerXx
@xXtrollplayerXx Жыл бұрын
Great video! Whats the name of the song in the background?
@BEN9116
@BEN9116 5 ай бұрын
can you do an updated version of this!
@RenkoGSL
@RenkoGSL 3 жыл бұрын
I noticed you stretching your wrists and went to Japan, do you usually do just one wrist stretch? Or do you know about the other one? Nikkiyo and kategashi are the two that complement each other well.
@javiercampos1668
@javiercampos1668 3 жыл бұрын
I got more from this than my college classes lol
@asdprogram
@asdprogram Жыл бұрын
A good advice for everyone: Never put any unnecessary calculations inside the brackets of the for loop. For instance what's wrong with this code: #include #include #include int main(){ int count = 0; for(int i = 2; i < 100000; i+=1){ char prime = true; for(int j = 2; j
@AgentM124
@AgentM124 7 жыл бұрын
welll, i would not get out of scope after the loop ended, so the value is still accessible and you can use i outside the loop that way :p
@mattigor5476
@mattigor5476 2 жыл бұрын
Excelente video omg!!! What IDE did you use in the video??
@rtdietrich
@rtdietrich 2 жыл бұрын
VisualStudio (not VisualStudioCode)
@lbsna3232
@lbsna3232 6 жыл бұрын
Which software you are using because I have turboc8
@GoldenBeholden
@GoldenBeholden 4 жыл бұрын
Your lamp looks like a renaissance painting.
@divinevine9413
@divinevine9413 6 жыл бұрын
i think: this is great even though he talks a bit fast thanks anyway :)
@chrissumrall8874
@chrissumrall8874 6 жыл бұрын
wow this was the best tutorial ive ever seen. all other tutorials go wayyy too fast and dont break it down. they assume we know a lot that we dont
@treya111
@treya111 4 ай бұрын
so at the end of this vid you said when that indepth vid comes out you'd put the link in the description but I didn't see it, so did you do that indepth vid in the later part of this series?
@Popart-xh2fd
@Popart-xh2fd 2 жыл бұрын
I think that if you use ++i instead if i++ in the for loop, the increment is done before the i
@crusaderanimation6967
@crusaderanimation6967 2 жыл бұрын
6:39 oh So that's why this syntax create infinite loop i trough that (;;) is some special case. (kinda else if sytuation when you might tough it's special case when it's just two seperate keywords)
@MateuszSwieszek
@MateuszSwieszek 5 жыл бұрын
what about for each loop?
@austinoquinn815
@austinoquinn815 Жыл бұрын
goto is obvi the best way to loop in C++. Use it whenever you can.
@crystalwulf1800
@crystalwulf1800 7 жыл бұрын
1:26 "Video up here". Which video? Where?
@cloudyplayzyt1679
@cloudyplayzyt1679 Жыл бұрын
If I wanted to ask the user to enter the input (their name) with the while and for loop,How would I do that?
@richardboyd6756
@richardboyd6756 4 жыл бұрын
Where did you get that lamp??
@rifathossain328
@rifathossain328 4 жыл бұрын
can we take input from user while loop running??
@krec348
@krec348 7 жыл бұрын
I arrived very soon this time xD
@pawprinting
@pawprinting 3 жыл бұрын
Is there any way to delay time inbetween these loops?
@candle-likeghost9523
@candle-likeghost9523 3 жыл бұрын
Quick Quiz: what is the difference between ++i and i++? Answer: | | | | | V Actually, ++i and i++ both returns some value. ++i returns the i that already plus 1 while i++ returns the i before the increment (before plus one). Funny enough, I learnt this from javascript.
@rajeshakhade7346
@rajeshakhade7346 6 жыл бұрын
How and on what based the condition is true ??? How the compiler comes to know about value of i variable??
Control Flow in C++ (continue, break, return)
8:20
The Cherno
Рет қаралды 188 М.
POINTERS in C++
16:59
The Cherno
Рет қаралды 1 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
Learn C++ With Me #11 - While, Do While Loops & Break/Continue
24:01
CONST in C++
12:54
The Cherno
Рет қаралды 394 М.
Should you learn C++?? | Prime Reacts
20:29
ThePrimeTime
Рет қаралды 323 М.
Learn JavaScript WHILE LOOPS in 8 minutes! 🔁
8:12
Bro Code
Рет қаралды 19 М.
How the C++ Compiler Works
17:55
The Cherno
Рет қаралды 784 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
While loops in Python are easy ♾️
6:58
Bro Code
Рет қаралды 317 М.
C++ Tutorial -   Loops In C++ [For Loop, While Loop, Do While Loop]
16:20
C++ for loops (#12) ➰
11:15
Bro Code
Рет қаралды 10 М.