Conditions - C++ Tutorial For Beginners #9
Skills:
Tool Use & Function Calling70%
Key Takeaways
This video tutorial covers conditions in C++, including if statements, else statements, and else if statements, with examples and explanations for beginners.
Full Transcript
it's not a game it's [Music] a what is going on guys welcome back to C++ tutorial Series in today's video we're going to talk about conditions so let us get right into it so I think in the fifth video of the tutorial series here we talked about comparison operators and their Boolean results and we also mentioned that they are going to be very important when we get to conditions and loops and now we're getting to conditions which are essentially just if statements so if you're already familiar with programming you know what if statements are uh actually if you're programming in Java or C you actually know how to write uh if statements if else statements in C++ because the syntax is the exact same so if you know how to write if else in Java you know how to write it in C++ if you know it in Python it's a little bit different uh differently but it's essentially pretty similar so if you understand it in Python you can also understand it in C++ and the only thing that you need to learn are the syntactic uh syntactical differences here whereas if you have never coded if you don't know about if else statements at all I'm going to explain it from scratch here as well and the idea is that up until now we had in a function a couple of statements and yes by the way you saw right I'm using namespace STD uh because by now you should already know that this is not the best practice way so we can do it for the sake of Simplicity however of course if you're working in a project don't do it like that it's not considered best practice however what we did in a main function is we always executed some stuff like C out something endline then we created variable and so on everything was executed step by step so we said see out Define something add something do something and then sooner or later we get to the end return zero um now this is not very conditional and as the name already says conditions make our code more conditional it's less linear and this means that we have certain conditions for executing certain statements uh and those conditions are specified with the so-called if statement so we say if and then in parenthesis we specify what has to be true in order for a certain block to be executed for example let's say we have a variable uh in a and we input a so we get user input for a like that and then we say okay if the input that we have just given to the program here if this input is larger than 10 then we're opening up a new block here by the way this is also a new scope so if we Define a variable in here it's not necessarily going to be um we're not going to be able to access it from the outside here so this is a block of code here and in here we can do something I don't know see out your number is larger than 10 very simple message and then so so this block right here if we just leave it like that what happens is we say if a equals 10 uh not equals 10 sorry it's larger than 10 greater than 10 if that is the case if this comparison here returns true that block is going to be executed otherwise it's just not going to be executed so right now we can see if I compile this program here um we can see I can enter a number let's say nine in this case and nothing happens we just get nine we input n and nothing happens whereas if I run this again and enter 99 for example it says your number is larger than 10 so as you can see depending on the input this block gets executed or not um and if we want to also specify what happens if this condition is not true we can use an else statement as well so we say if a is larger than 10 then do this otherwise if this is not the case so else and we open up a new block here if this is not the case we say else see out your number is not larger than 10 you can also write is less or equal to 10 so we can go ahead and run this again and you're going to see that uh we have seven and it says your number is not larger than 10 if I say 99 your number is larger than 10 if I say 10 it's going to say your your number is not larger than 10 or greater than 10 I think greater than 10 is actually the term that we want to use here I'm not sure if larger is correct here um yeah so what you can see here is that we have certain conditions and certain pieces of code that get executed based on that condition now what do we do however if we want to check from multiple conditions so let's say I want to check if a is larger than or actually let's let's change this to 100 here I want to know if a is greater than 100 and if it's not greater than 100 I want to know if it's at least greater than sorry greater than 50 so if this is not the case I want to know if it's greater than 50 and if it's neither greater than 100 nor greater than 50 I want to print something else and in this case I can go ahead into the else Branch here and formulate another if statement so I can say okay if it's not larger than 100 I can say if so inside of the else Branch here I say if a is greater than 50 if that is the case we can get this C out in here and say your number is not greater than 100 but greater than 50 and then we can add another else Branch here and say if even that is not true we can say see out your number is not greater than 50 end line so this is a very trivial example but we can compile it and enter something like 70 and you can see your number is not greater than 100 but greater than 50 we can do the same thing with 120 your number is greater than 100 then we can say 40 your number is not greater than 50 if I say 50 greater not greater than 50 if I say 100 it's not greater than 100 but greater than 50 so as you can see we can do it like that but we can also do it in a different way we can use something called else if which is essentially the same thing or a very similar thing but it's written differently we can say else if in one line here else if a is greater than 50 then do something so in this case come on I'm going to just simply print greater than 50 and then I can still append one house Branch to those so here I can say less or equal to 50 and if we run this here we're going to see that we have the same functionality so 66 for example is greater than 50 12 is less or equal to 50 and 190 is greater than 100 so you can also write it like that so that's it for today's video hope you enjoyed and hope you learned something if so let me know by hitting the like button and leaving a comment in a comment section down below and of course subscribe to this Channel and click the notification Bell if you don't want to miss a single future video for free other than that thank you very much for watching see you in the next video and bye [Music]
Original Description
Today we talk about conditions in C++.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
🐍 The Python Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
The Only AI Tools a Small Business Actually Needs in 2026
Dev.to AI
I Built an AI Life Planner the Month I Graduated and Switched to Linux Halfway Through
Dev.to · Hilal
Your Second Brain Is a Graveyard. Your AI Has Amnesia. (Part 1)
Medium · AI
The Python Automation Business I Started With 200 Lines of Code Eventually Replaced My Freelance…
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI