CONDITIONS and BRANCHES in C++ (if statements)

  Рет қаралды 298,331

The Cherno

The Cherno

7 жыл бұрын

Twitter ► / thecherno
Instagram ► / thecherno
Patreon ► / thecherno
Today we're going to be taking a look at conditions and branches in C++, which basically means if, else if, and else statements. This is an important part of logical programming where we decide to execute certain blocks of code depending on a certain condition. We go pretty in-depth in this video so make sure you watch until the end!
Linked Videos:
Debugging ► • How to DEBUG C++ in VI...
How the C++ Compiler Works ► • How the C++ Compiler W...
Variables in C++ ► • Variables in C++
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

Пікірлер: 451
@kauht
@kauht 4 ай бұрын
6 years later and this is still the highest quality c++ tutorial on the internet, thanks!
@weltgeist.
@weltgeist. Ай бұрын
ikr
@zyris863
@zyris863 7 жыл бұрын
I'm in college and you explain this stuff a lot better than my professors. Thank you so much for this. Keep it up!
@spattermann5809
@spattermann5809 6 жыл бұрын
When the professors or TAs (teaching assistants) actually speak english (not a given) they don't actually teach instead they are culling. You only pass if you can teach yourself from over-priced and badly written textbooks or already know the material. To say I am disenchanted with US higher education is a broad understatement.
@klarnorbert
@klarnorbert 4 жыл бұрын
This is why you don't go college if you want to do software engineering.
@guilhermezardo7671
@guilhermezardo7671 3 жыл бұрын
@@klarnorbert you can do both
@appsenence9244
@appsenence9244 2 жыл бұрын
why would anyone attend university?
@yeadatwunyt8004
@yeadatwunyt8004 2 жыл бұрын
@@spattermann5809 It's not just the US
@henrikhey4184
@henrikhey4184 7 жыл бұрын
Please make some assembly tutorials!
@user-gj7nd7rb4v
@user-gj7nd7rb4v 7 жыл бұрын
why
@merijnvinea3546
@merijnvinea3546 7 жыл бұрын
Henrik Hey Do it!!
@henrikhey4184
@henrikhey4184 7 жыл бұрын
cronnostiger64 personally, I think that assembly is extremely useful, especially when it comes to optimization. If you look at the source of any major game engine they all have parts written in assembly.
@henrikhey4184
@henrikhey4184 7 жыл бұрын
***** No problem! Check out the source for the idtech3 engine (doom3 engine) sometime it's all on github and really shows off the full power of c++ :) it's one of my favorite piece's of source to read through!
@henrikhey4184
@henrikhey4184 7 жыл бұрын
*****​​​​ Absolutely! I would however recommend reading through the Idmath library in the project in that case :). I understand computer graphics somewhat, I still struggle with the API's however lol(opengl and vulkan), as for learning it, I'd recommend the tutorials offered by the cherno, thinmatrix(even though he uses java, the GL is the same) also recommend checking out the computer graphics series by computerphile(they give an awesome explanation of things like how matrices work, how the scene is rasterized and how the depth buffer is created!). And overall reading through blogs is also extremely useful, just remember to start with the fundamentals and work your way up!
@danielandrejczyk9265
@danielandrejczyk9265 7 жыл бұрын
"Compiler will do some magic... and you'll get rekt" XD
@sablanex
@sablanex 7 жыл бұрын
Best part :)
@martingaens2073
@martingaens2073 4 жыл бұрын
i thought it was 'get rekt' lol. Even youtube auto generated subtitles say it's get rekt.
@joshuarowe8410
@joshuarowe8410 4 жыл бұрын
@@martingaens2073 holy shit that's pretty funny. Im surprised the auto-generated subtitles use 'rekt'
@martingaens2073
@martingaens2073 4 жыл бұрын
@@joshuarowe8410 yeah, I guess it has to adapt to the meme culture
@danielandrejczyk9265
@danielandrejczyk9265 4 жыл бұрын
Fixed wrecked to rekt... nice
@12isaac00
@12isaac00 5 жыл бұрын
"else if is just an if nested into an else" my life is a lie
@VivekYadav-ds8oz
@VivekYadav-ds8oz 4 жыл бұрын
_EDIT: I'm letting the old example rot at the end, as it caused a lot of confusion. You'll eventually see even this example is wrong, but it better illustrates my thought process at the time._ If "else if" is just a nested if into an else, then this block of code should compile, but it doesn't: #include using namespace std; //Sorry guys I couldn't resist int main() { int x = 7; if (x == 7) cout
@beesknees8296
@beesknees8296 4 жыл бұрын
@@VivekYadav-ds8oz Not sure if I am completely understanding what you're saying but the reason that code does not compile is because you cannot have a stand alone else. If...else come in pairs and else are linked to the closest incomplete if. Your first else is paired with if and the second else is not paired with anything. That is why the program doesn't compile.
@NphiniT
@NphiniT 4 жыл бұрын
@@VivekYadav-ds8oz else-if is a nested if into an else not else. That is, else is not a nested if into an else!
@NphiniT
@NphiniT 4 жыл бұрын
@@beesknees8296 You don't get it LOL!
@bharat_132
@bharat_132 4 жыл бұрын
I kinda understand what you say... Let me try to explain , I may be wrong... Plzz feel free to correct me...ill just wright the code part ,......,............. If(x==3) cout
@thepollardbull
@thepollardbull 3 жыл бұрын
Good distinction of programming falling into two categories, 1. Mathematical programming 2. Logical programming
@Steven-tw7iz
@Steven-tw7iz 7 жыл бұрын
I think an assembly tutorial/video would be a great idea. It really shows how the code write will end up working down at the metal. And gives new people a look into just how much the compiler can optimize your code without you realizing
@straddlescout1220
@straddlescout1220 6 жыл бұрын
"The little bit extra" This is why I love this series
@kickbuttowsk2i
@kickbuttowsk2i 4 жыл бұрын
that "else if" part alone convinced me to watch the entire series
@TheRossmclane
@TheRossmclane 6 жыл бұрын
Please make videos on assembly! These are so cool.
@BOTHLine
@BOTHLine 7 жыл бұрын
Yes, please an assembly tutorial!
@Tomasxt25
@Tomasxt25 7 жыл бұрын
I would love some assembly videos!!!! Great video anyways
@w3w3w3
@w3w3w3 4 жыл бұрын
Great video again. Really interesting as well, and you explain the 'ins and out' of things as well, instead of just typing code and us copying it with no real understanding, which a lot of other people just do. Thanks for putting in the time to make these videos and series.
@woolwizard1967
@woolwizard1967 4 жыл бұрын
It's so fascinating how i can still learn stuff about these things, that i already used for years in your videos. Simply amazing
@xristosbart8217
@xristosbart8217 7 жыл бұрын
Please, a video for a brief explanation in assembly would be a good idea, not in great extent, just enough to follow debugging. Also, I think you should start the OpenGL series in parallel looking forward to that! Great series, we appreciate the fact that you go deeper in some points, it gives us a better understanding. Keep up the great work!
@qidex
@qidex Жыл бұрын
You cover a lot of basic things I'm already thoroughly familiar with, but you do it in such a clear progression of explanation. You also still have some things that are new to me, like the dissassembly view. May not be what I personally need, but very well done.
@jeremygong4190
@jeremygong4190 2 жыл бұрын
I love your vids not only because every time I've learned so many new tricks within the old boundary of my knowledge; but also, I was able to understand the principle and the reasoning behind it. Those vids do make everything look so transparent, and do enhance my thought to view the codes in a much grander perspective. It feels like the difference between solving a physics problem using mere equations from the book (seek-and-match progress) and solving this problem by your understanding of its mathematical principle (deriving your own equations). GROUNDBREAKING lessons! I will spent the rest of two days finishing every single vid from this watch list!
@nfrancisj2122
@nfrancisj2122 5 жыл бұрын
You talk so much, and I love it. The depth of your explanations really helps explain why things work the way they do. Thanks!
@RomeWithTheHEMIs
@RomeWithTheHEMIs 7 жыл бұрын
Much love, Yan! I really enjoy these vids, and appreciate the dedication you've shown. Asm tutorials would be amazing
@kenlaw3376
@kenlaw3376 6 жыл бұрын
Thank you! You are light years ahead of all other tutorials on KZbin because you take time to explain. Most others just type fast and say, don’t worry about what I’m doing, just do it. You are the best.
@foti4822
@foti4822 Жыл бұрын
Love this series so far. I like how you show things like viewing the disassembly and debugging in visual studio. 👍
@harshalrathi8332
@harshalrathi8332 2 жыл бұрын
Hi Cherno, this series is well bought up, thank you for detailed explainations, mistakes and corrections, some new pts. and explaining via registors too. This was super fun and I hope you keep making new such videos. Thanks...😊😊😊😊
@mbyb6817
@mbyb6817 4 жыл бұрын
Please make a video with examples of logic vs mathematical program flow.
@itsNixy
@itsNixy 2 жыл бұрын
@The Cherno Your C++ series is absolutely amazing. Please, please do make a series on Assembly as well! Thank you for your great explanations. As someone with some previous experience, I still learn new things in almost every one of your videos in this series.
@amirrezasadeghi5755
@amirrezasadeghi5755 4 жыл бұрын
thanks for explaining things from scratch. it is so valuable to see what actually is going under the hood of the c++. thanks a lot.
@dani485b
@dani485b 7 жыл бұрын
20:58 "else" "hand gestures* " if" have to love that explanation, nice video as always Cherno! :)
@BigCatSoftware
@BigCatSoftware 3 ай бұрын
So far this series is really intuitive and easy to learn from. Thank you Cherno!
@pf8662
@pf8662 3 жыл бұрын
Please assembly tutorial! Your explanation is so clear and detailed! I had learned so much from you everytime despite my school had teach the topic before.
@arkemal
@arkemal Жыл бұрын
I loved the Disassembly part, well done Cherno!
@jakhongirnematov5588
@jakhongirnematov5588 3 жыл бұрын
This series is extremely helpful, thanks for the simple yet deep explanations. And yes, if you have time can you make an assembly tutorial?
@Ferocious_Imbecile
@Ferocious_Imbecile 2 жыл бұрын
Yes please an Assembly tutorial.
@LifexLess
@LifexLess 3 жыл бұрын
You deserve so many more subscribers/views. Thank you for your videos.
@habsburger8500
@habsburger8500 4 жыл бұрын
@Cherno Best C++ Teacher! I have been looking around for 2 Years. You are the REAL TheNewBoston! And please... YES, do something on Assembly. Would love so much. Thanks for everything Cherno.
@vidhishetty4130
@vidhishetty4130 5 жыл бұрын
Thankyou so much for all your Cpp tutorials. I have learnt so much from you.
@ascii6715
@ascii6715 5 ай бұрын
I'm a computer science student and I am trying to learn C++ not for academical purposes but just a fun. I watched so many computer science videos on KZbin. Every channel I watched just explain "How does it used?". It was not satisfied. My friend suggested to me watch you and now hopefully, I listened him. I'm glad to meet your channel.
@MarcusTL12
@MarcusTL12 7 жыл бұрын
YAAAY! Best time of the week :D
@linavabai8470
@linavabai8470 Жыл бұрын
Thanks! I'm learning so many new stuff from your videos.
@ButterBeanCW
@ButterBeanCW 2 жыл бұрын
I don’t even understand assembly, but to see you step through the registers with the code beside it made so much sense!
@mamazu1995
@mamazu1995 7 жыл бұрын
Great in depth view of a very basic concept. You have talked about optimization and one thing that I really felt missed in this video was lazy evaluation.
@kasiviswanadhsripada
@kasiviswanadhsripada 2 жыл бұрын
Hi Cherno! thanks for the video series.
@madhuhadas15370
@madhuhadas15370 3 ай бұрын
I am glad I found this channel. Thank you very much.
@ommaswale1454
@ommaswale1454 Жыл бұрын
can't believe this cool playlist was created 6 years ago
@kanutaro3426
@kanutaro3426 Жыл бұрын
The dissassembly part was brilliantly explained, first time I'm actually understanding this
@augustlehman6462
@augustlehman6462 6 ай бұрын
great! tutorial, in depth tutorial, on not only C++ but on computer programming in general; many thanks,
@richardrisner921
@richardrisner921 3 жыл бұрын
What I learned about C++ today: "anything really goes" This is even better than Python!
@adrianoldchannel2494
@adrianoldchannel2494 6 жыл бұрын
Wow. Interesting. I'm so in love with C++
@fendoroid3788
@fendoroid3788 7 жыл бұрын
do you code like this { } or like this { } ?
@pradyumnkejriwal3007
@pradyumnkejriwal3007 7 жыл бұрын
Fendoroid In functions, 1st one In if, while, etc. statements, 2nd one
@lewisb8634
@lewisb8634 7 жыл бұрын
Fendoroid Always the second one. I find it a lot clearer, although I can understand why people may find the first one clearer. Which one do you use?
@jonatanahnh
@jonatanahnh 7 жыл бұрын
Depends on the language convention For example in js the convention is { } but in c { }
@resantic2256
@resantic2256 7 жыл бұрын
{ } Makes it easier to see which brackets make up a block together
@fendoroid3788
@fendoroid3788 7 жыл бұрын
Lewis B I used to put the open brace on a new line, but now I put it on the same line: it looks more compact.
@hexlo514
@hexlo514 6 жыл бұрын
If you could do a series on assembly(IA-32), that would be amazing! Started software engineering not too long ago and this series is of tremendous help. Keep it up :D
@praveshgaire3437
@praveshgaire3437 5 жыл бұрын
Always learn new things from you (else if), never skip easy topics.
@sofianbenhamman2038
@sofianbenhamman2038 3 жыл бұрын
yes. we want the assembly video pls. You are the best at teaching!
@greob
@greob 7 жыл бұрын
22:15 this is precisely why I am super excited about your tutorials. I'm really keen on understanding what makes, and how to make efficient code. Every time I use a condition statement, I freak out in my head. But I never know how to optimize my code. Thanks for doing these great videos. :)
@mallelasaicharan6257
@mallelasaicharan6257 Жыл бұрын
this is a really UNDERRATED channel.
@nghiavutrung6419
@nghiavutrung6419 5 жыл бұрын
The way that you teach is very easy to understand. I am learning assembly, could you make a series video for that?
@kriszenn1125
@kriszenn1125 3 жыл бұрын
"branching makes your program slower" *glances at yandere dev*
@perapera68
@perapera68 5 ай бұрын
you explain so well ❤❤❤
@kenedymatiassoportella808
@kenedymatiassoportella808 2 жыл бұрын
That is gold! Thank you.
@Mark-xh6tl
@Mark-xh6tl 5 жыл бұрын
Only someone whose mind would be blowned by finding out else if is not a keyword would be this enthusiasic about all these details.
@vishnuks6252
@vishnuks6252 4 жыл бұрын
Excellent explanation..
@raghavsrivastava2910
@raghavsrivastava2910 3 жыл бұрын
You are amazing. Please make a course on x86-64 and arm assembly. I really love efficiency.
@rishi3
@rishi3 5 жыл бұрын
yes , we want some assembly tutorials
@mat13channel
@mat13channel 4 жыл бұрын
You can replace logical programming by doing mathematical operations instead? Wow, I am really intrigued in what you meant by that... I hope there'll be such example in later lessons.
@h.hristov
@h.hristov 7 жыл бұрын
Thanks for this video :)
@JFrameMan
@JFrameMan 7 жыл бұрын
I wish I had learned programming from the beginning the way you're teaching this.
@shreyas908
@shreyas908 4 жыл бұрын
hey cherno your videos and explanation is awesome i want to learn about assembly language i would appreciate it !! if you could make some videos on this topic
@lreporte
@lreporte 4 жыл бұрын
this is a masterpiece
@wooolly1722
@wooolly1722 4 жыл бұрын
Please do any Assembly tutorial some day please!! I've wanted to understand Assembly more for the longest time.
@breachplanting7398
@breachplanting7398 5 жыл бұрын
deep and detail!
@rohitkumarshrivastava9693
@rohitkumarshrivastava9693 2 жыл бұрын
Please make a video on assembly language. There are other video available but you explain things really well.
@abhinaybandaru9953
@abhinaybandaru9953 6 жыл бұрын
Great Work, Could you provide some exercises in your way to work with, that would be awesome.! Thanks
@sairam332
@sairam332 3 жыл бұрын
I really like this channel. Thanks Bro.
@sal96ali
@sal96ali 4 жыл бұрын
Hi, thank you so much. You are doing a great series
@asifkhan-mr8nj
@asifkhan-mr8nj 8 ай бұрын
great video
@chainonsmanquants1630
@chainonsmanquants1630 3 жыл бұрын
Thanks !
@palmasalazar2113
@palmasalazar2113 Жыл бұрын
¡Te amo cherno! Sigo esperando tu video acerca de ensamblador.
@motionsmoments6254
@motionsmoments6254 3 жыл бұрын
I liked the videos so much that at this point I click the like button before actually watching the videos... :)
@abbadkamel8839
@abbadkamel8839 5 жыл бұрын
wooow a lot of coool things u show them to us thanks u again nd again
@Alexithymiander
@Alexithymiander 5 жыл бұрын
Such teaching. Wow.
@Plasticcaz
@Plasticcaz 7 жыл бұрын
I've have a little knowledge about assembly and machine code, but it still seems quite foreign to me. I'd not be dissapointed to see one or more tutorials dedicated to assembly.
@error303
@error303 Жыл бұрын
When I was using unity and C#, I figured out the else if thing on my own.
@lokeshgubbala622
@lokeshgubbala622 8 ай бұрын
this integrated environment teaching helps us a lot!!!!! ✌️
@DTQC
@DTQC 4 жыл бұрын
wait, how can you can you pointer of char arrays? at 19:20? Wouldn't that just compare the address of the char arrays and only works by chance due to a lucky compiler optimization?
@ShonePizza
@ShonePizza 6 жыл бұрын
Thx, my native lang is russian, but it's so easy to understand your speech.
@davidfrogley7117
@davidfrogley7117 2 ай бұрын
Please note that the `ptr == "Hello"` works not because of the result of a string comparison but because the compiler reused the identical "Hello" c-strings (instead of creating two separate ones) and compared memory addresses (so clearly a c-string's memory address is equal to its own memory address, hence the comparison results in "true"). For string value comparison, use strcmp (for c-strings) or use C++ strings (std::string).
@jour785
@jour785 Жыл бұрын
The way that else if is really made blew my mind lmao
@dimpap9659
@dimpap9659 2 жыл бұрын
Finally someone who teaches cpp in a proper & in a way that is easy to understand ! Our Professor also was trying to tech real cpp, the problem was that he doesnt understand how hard this things are if you just start to learn cpp, probably cause he's doing it for so long. Ty you saved me some cp :)
@choosyguytest719
@choosyguytest719 5 жыл бұрын
else if blew my mind :)
@jag5260
@jag5260 4 жыл бұрын
The best video tutorials. c++ i ever watch very detailed and easy to understand . 👍👍 specially in game engine programming. Can you make a tutorial about UI ingame programming in c++ visualstudio and its function like skills and invetory system with xml and external UI Dds file, client to server. 😃😆
@mohamedaminetriki9648
@mohamedaminetriki9648 5 жыл бұрын
I wanna thank you ! you are great
@nicklandreth2527
@nicklandreth2527 4 жыл бұрын
I would also be interested in learning some assembly for a deeper understanding if you ever get there.
@ashwoodson1649
@ashwoodson1649 5 жыл бұрын
Wathing your c++ series, you mentioned doing assembly tutorials. Yes please.
@tannishkmankar3998
@tannishkmankar3998 Жыл бұрын
Still working as of today, ty!
@andreashadjigeorgiou1596
@andreashadjigeorgiou1596 4 жыл бұрын
I would definitely be interested in Assembly videos
@jiashuwang4446
@jiashuwang4446 Жыл бұрын
something interesting: if you define two integer variables: a and b and then initialize it with 0 and 1 now here is a if: if(a&&b++){ ; } and after the if, the b is still 1 but if we change the condition: if(a||b++){ ; } this time b == 2 when I encountered this, I was amazed that the PC was not as stupid as I once had thought. It is clear about the condition structure. If there is a && structure, judge will end immediately after finding a false proposition(im a beginner, maybe there are some misunderstandings)
@Luctaris
@Luctaris 5 жыл бұрын
Would have been nice if you covered the switch statement for larger branching, but either way nice vid.
@painfullyhuman
@painfullyhuman Жыл бұрын
it pisses me off that after reading a 1200-page book your videos are not only more succint but more helpful than anything in it
@WindPortal
@WindPortal 4 жыл бұрын
You're great :)
@raufnasery2373
@raufnasery2373 5 жыл бұрын
Thank you 💪💪💪💪💪
@0x54dotexe
@0x54dotexe 8 ай бұрын
yes please we want Assembly crash course
@user-ln5eb1hb8h
@user-ln5eb1hb8h 10 ай бұрын
If else if is not a keyword, how are we able to place an else at the end of the control block? Was just curious. But this tutorial is by far the best I have seen so far
@chomiyeons
@chomiyeons Жыл бұрын
ive learned sm from this series!! u r truly a life saver as ive been trying to learn c++ for some time but never rlly got anywhere. with this series it rlly helped me understand c++ and how it works.
@drv5037
@drv5037 5 жыл бұрын
YES. MAKE ASSEMBLY TUTORIALS!!!
BEST Visual Studio Setup for C++ Projects!
12:08
The Cherno
Рет қаралды 478 М.
POINTERS in C++
16:59
The Cherno
Рет қаралды 1 МЛН
UNO!
00:18
БРУНО
Рет қаралды 3,5 МЛН
Это реально работает?!
00:33
БРУНО
Рет қаралды 4 МЛН
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
How to DEBUG C++ in VISUAL STUDIO
19:20
The Cherno
Рет қаралды 469 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 780 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 242 М.
Loops in C++ (for loops, while loops)
12:20
The Cherno
Рет қаралды 400 М.
I Rewrote This Entire Main File // Code Review
16:08
The Cherno
Рет қаралды 151 М.
why do header files even exist?
10:53
Low Level Learning
Рет қаралды 385 М.
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel
Рет қаралды 137 М.
UNO!
00:18
БРУНО
Рет қаралды 3,5 МЛН