Control Flow in C++ (continue, break, return)

preview_player
Показать описание


Today we're talking about control flow statements in C++. Control flow statements allow us to change the "flow" of our program so that we can change what it does under certain circumstances. This is another one of those really important fundamentals that you'll want to make sure you understand really well.

Number one strategy to learn this? Start writing some code and see what these statements do! Additionally, step through the code line-by-line using the debugger if you're still confused about what actually happens.

Рекомендации по теме
Комментарии
Автор

Honesty, the best C++ videos out there... Hands down.

ToxicityGameDev
Автор

I have to say that:
6 years ago I started a course Computer Engineering... I studied C++ Continuously for some time and i consider myself to be a good c++ programmer.
I am watching those videos just to widen all my knowledge and fill some blank spaces in my memory, and your videos are just excellent.
If I were to teach c++ for someone I would definitely use your videos

orley
Автор

A bit off topic but I'm happy at how much the quality of programming tutorials have raised. I remember when I first started teaching myself most tutorials were people with heavy accents and bad mics trying to explain something but you had to raise the quality to 360p and squint to see the code.

TheElitedeath
Автор

Hey Cherno, I’ve been watching your videos for years now back when you started the 3D Java game tutorial from scratch when you were known as TheChernoProject and I just have to say thank you for everything, you have always had amazing tutorials and now that I’m starting a degree in computer science I’ll know where to look when I need help. Keep being the GOAT for programming

Bloodandeath
Автор

I can't overstate how much sunlight helps these videos. I'm always so happy when the next one begins and it's all bright and promising.

radekseky
Автор

In case some of you wanted to know what "instruction pointer" is, this is the answer from Bard:

```
In C++, the instruction pointer (IP) is a register that holds the address of the next instruction to be executed. The IP is incremented after each instruction is executed, and it is used to control the flow of execution of the program.

The IP is a critical part of the CPU's instruction execution pipeline. When the CPU fetches an instruction from memory, it first loads the address of the instruction into the IP. The CPU then uses the IP to access the instruction in memory and decode it. Once the instruction has been decoded, the CPU executes it.

The IP is also used to implement control flow statements such as loops, conditional statements, and function calls. When a control flow statement is executed, the IP is updated to point to the next instruction to be executed. This allows the CPU to execute instructions in a non-linear order.

The IP is a volatile register, which means that its value can change at any time. This is because the IP is updated whenever the CPU fetches a new instruction from memory or executes a control flow statement.

The IP is an important part of the CPU's architecture, and it plays a critical role in the execution of C++ programs.
```

fahmiabdulaziz
Автор

When he said: "Let's take a look at break.", I first understood: "Let's take a little break." LOL

mistervoldemort
Автор

Cherno, I am in school for Game Design, and these videos help me make sense of the confusing C++ textbook I have been reading. I am very grateful you made these videos, you are an excellent teacher!

ericsankey
Автор

When you have double, triple, etc., nested-loops, then breaking out entirely from the nested-loops is somewhat cumbersome using the 'break' keyword. In that particular case, it is totally OK if you use the dreadful 'goto' keyword to break out entirely from the nested-loops via jumping towards a label strategically positioned just outside the nested-loops. In my opinion, this technique should have been mentioned alongside the control flow statements which have been presented in this video.

deltarambo
Автор

- Return will exit the function. (Like return 0)
- Continue skips the current iteration of the loop and the control of the program goes to the next iteration
- Break ends execution of the nearest enclosing loop or conditional statement in which it appears

GenericPhantom
Автор

I have a job technical test and have been watching these videos on 2x speed. Very possible and very easy to listen to. :D (Just gotta brush up on C++)

sir.niklas
Автор

Great series! It's been years since the last time I coded c++ and this is the perfect resource to start again.
Just a note on
if((i + 1) % 2 == 0)
I would've used just
if(i%2)

CaNNaDark
Автор

Commenting for your exposure. The best channel on YouTube for C++ !!!

roja
Автор

This C++ series is very satisfying (edit: correct my grammar)

candle-likeghost
Автор

The Break Point really helps me understand!

shaharyarahmed
Автор

Hi there! I really enjoy your tutorial. I'm no longer a total beginner, but also far from expert. I'm looking forward to keep watching next lessons. BUT, what would be really great, if you could give some practical exercise to try out and better remember new topic. or maybe point to some external source of tasks to do, while learning. Because just listening isn't very effective way to learn.

devgamez
Автор

Everything is perfect, even the whiskey in the background.

nesumvladi
Автор

0:46 In terms of power scaling, I would say exit() wins ^^ In terms of travel ability, I gotta give it to goto and goto labels ^^

astralchan
Автор

Amazing videos. Thank you a million times

ohadchaet
Автор

I love it.... clean and straightforward!! (Honestly, you are better than my professor... :P)

carolinekim