Golang Tutorial #7 - Conditions & Boolean Expressions
Skills:
LLM Foundations80%
Key Takeaways
This video tutorial covers conditions, boolean expressions, and conditional operators in Golang, including comparison operators and their usage with different data types.
Full Transcript
[Music] hello everyone and welcome back to the golang tutorial so in this video what I'm gonna be doing is talking about comparison operators and boolean expressions otherwise known as conditions that's why I usually like to phrase them now there's a bunch of words again you've probably heard me say all these random things that you don't understand don't worry about the vocabulary behind it so long as you understand the concept that is totally fun so what I'm gonna show you here is what is known as the comparison operators now the comparison operators us these are pretty well standard across almost all programming languages sometimes they added a few extra or there's some that are a little bit different go is pretty standard the operators we have is less than greater than less than or equal to greater than or equal to is equal to and not equal to so these are kind of v6 operators we can use to compare different values so sometimes and often times actually we want to check if something is equal to something else if something is less than or greater than something else and you know there's a lot of math that will come into programming when we can do these kind of things so we have those operators now how do we use them these work very similarly to the arithmetic operators that I've shown you showed you before except when we write an expression that contains them that expression will result in either being true or false so rather than returning some numeric value like we might have when we added two numbers this will return either true or false based on the comparison that happened so if I do something like Val colon equals X less than 5 well let's look at this is X less than 5 no it's not so you would assume that this is gonna be what then well this should be the value false so if I actually run the code and look down in the console here oops Y declared and not use so let me just comment that out but if we say X less than 5 and we run this we get the value of false because X is not less than 5 but what about X less than or equal to 5 well that's gonna give us the value of true so let's run this and have a look and we get true so the way this operator works is it pretty much says is X less than or equal to 5 and the basic way to see if you understand how these work is just read it as a sentence right I say is the variable X and then read the name of the operator so less equal to the value of five and you can pretty much determine by yourself whether that's gonna be true or false now commonly we'll also do something like double equal sign so two equal signs since four is equal to it checks for equality between these two values so it checks if X is equal to the value of five now in this case it is so we will get the answer of true now it's important to note that like I said these work very similarly to the arithmetic operators and that whatever is on the left-hand side and the right-hand side need to be the same type so if I go ahead and do something like you know y equals 6.5 and then I say X equals equals Y well obviously we know that's false but this is actually invalid syntax we actually can't write this because this is not the same type as this this is a float and this is an int so if we wanted to do this comparison then we would have to convert either this to an int or this to a float so it would likely make sense to convert this to a float so we're not losing any information float 63 float64 like that and now if we run this we actually get an answer of false now the other comparison we can do that's like this is not equal to you can think of this as just the reverse of is equal to right so if they are equal then not equal to will be false if they're not equal then not equal two will be true right pretty basic again you can just read the name and that should make sense so let's see we get in this case false does not equal wait what the heck I don't think I saved the program let me run this one more time that should be the value true okay yeah so true there we are I was confused before okay so there we go that's the basic operators I mean like I could go through and show you all of them but I don't think there's too much value in doing that if you understand what these mean what I will say though is I've called like this one less than and this one greater than um these don't really have like a formal name at least in my opinion it just really based on where you write things like if I write you know something that's less and greater here then the same expression can be defined by just putting less greater here right like these are the same things if you just flip where the two values are so that's something to keep in mind that works the same obviously with the equal signs too so there's not one that's less than and one that's greater than it depends where you put the variables these could be equivalent expressions now you can also do stuff like this right against a float 64 X like plus 1.5 does not equal Y we can you know combine expressions and do that so let's have a look at this here and see what we get on this and we get false because these actually are the same value so the way this works is we actually evaluate any arithmetic operators before we go ahead and do this comparison operator so you can do things like add 1.5 check if it's less than a value you know multiply something within the same line as wherever this comparison operator is and right here what I've been doing is storing this in a variable we don't necessarily need to store that in a variable in fact I could take this expression here and just paste it right into the FMT dot print line and there won't be any issue with that idle give us actually the exact same thing we've just omitted the step of making that variable so there we go we get false now I'll go back what I want to show you now is comparing strings and some other data types so not just you know integers and floats so let me like a string Tim let me make a string Tim here with a capital T now my question is pretty much what do you think is gonna happen if I try to compare these two values so I say if X is equal to Y is that gonna give me true or is that gonna give me false well let's have a look at it and run it we are going to get the value of false because this capital T is not the same as this lowercase T so when we're comparing strings all of the characters in that string including any white spaces or anything need to be the exact same so just keep that in mind because a lot of people will make that mistake when they're doing this comparisons so let's how you do on strings now my question is can I do something like this can I do X is less than Y let's see is that a valid thing to write well let's run this code and see what we actually end up getting so we actually get false so the way that this works is we can actually compare strings using less than and greater than operators and what that will do is compare what's known as the ASCII value of the characters starting from left to right so a better way to do this is something like you know a and B so is a less than B well if you think about an alphabet right a comes before B so it would be less than B but is capital a less than B actually no it's not and the reason it's not is because cap letters um in the ASCII code table which is I can't really I guess I could pull up a photo I'm not gonna do that right now but the way it works is each letter has one number that represents it in the computer and a capital hit a happens to be 65 and I believe that lowercase a is like 97 or 96 or so it's like 90 something the idea is though it goes all the uppercase letters so starting at 65 and then after all of those have finished it starts at lowercase a and goes up so any lowercase letters will be actually greater than any of the capital ones and I'll prove this to you because we say is luck X less than Y and in this case well this would actually be true but if I swap this around and maybe actually let's make that see for a better example and we run this we are going to get the value of false because B is actually a greater value than C and that's kind of the idea behind that so you can compare strings you can compare characters as well I believe so characters are actually defined with single quotation marks so I could compare the equality between like to sees like check a double equal sign let's have a look at this here and we get the value true right so that's the idea behind this you can compare pretty much any type of objects for some things when we start getting more advanced it'll become a little bit more complicated but that's the idea behind comparison operators understand that these return true or false and yeah if you understand that you are ready to move on to the next video where we talk about chained conditionals so with that being said I hope you guys enjoyed if you didn't make sure you leave a like subscribe and I will see you in the next one
Original Description
In this golang programming tutorial I cover conditions, boolean expressions and conditional operators. These are used to compare values and check for equality.
🎙 Subscribe to my second channel for weekly podcasts! https://www.youtube.com/channel/UCSATlCAUi7R0Ik-wsZb2gOA
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
https://tech-with-tim.teachable.com/p/the-fundamentals-of-programming-with-python
📸 Instagram: https://www.instagram.com/tech_with_tim
🌎 Website https://techwithtim.net
📱 Twitter: https://twitter.com/TechWithTimm
⭐ Discord: https://discord.gg/pr2k55t
📝 LinkedIn: https://www.linkedin.com/in/tim-ruscica-82631b179/
📂 GitHub: https://github.com/techwithtim
🔊 Podcast: https://anchor.fm/tech-with-tim
💵 One-Time Donations: https://www.paypal.com/donate/?token=m_JfrPK7DsK4PLk0CxNnv4VPutjqSldorAmgQIQnMozUwwQw93vdul-yhU06IwAuig15uG&country.x=CA&locale.x=
💰 Patreon: https://www.patreon.com/techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
⭐ Tags ⭐
- Tech With Tim
- Go Tutorial
- Golang Tutorial
- Go Programming Tutorial
- Golang conditions
- Go Conditions
⭐ Hashtags ⭐
#GO #Golang
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 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
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Guardrails AI: preventing LLM hallucinations and enforcing output structure
Dev.to AI
I Built a Dead-Simple API Gateway for My Local LLMs in 50 Lines of Python
Dev.to AI
Build with Open-Weight LLMs: A Developer's Guide to API Integration
Dev.to AI
How to Add Real-Time Web Search to LlamaIndex Agents
Dev.to · Cecilia Hill
🎓
Tutor Explanation
DeepCamp AI