🥳 GOSKILLS TURNS 10: Get 10 days of free access with code 10YEARS

GoSkills
Help Sign up Share
Back to course

Comparison Operators

Compact player layout Large player layout

Locked lesson.

Upgrade

  • Lesson resourcesResources
  • Quick referenceReference
  • Transcript
  • Notes

About this lesson

How to compare two or more items with Ruby.

Exercise files

Download this lesson’s related exercise files.

Comparison Operators.docx
58.7 KB
Comparison Operators - Solution.docx
58.7 KB

Quick reference

Comparison Operators

Comparison Operators allow you to compare things.

When to use

Whenever you need to compare two or more things, use comparison operators.

Instructions

Here's a list of comparison operators:

==   Equal To
!=    Not Equal To
>     Greater Than
<     Less Than
>=   Greater Than or Equal To
<=   Less Than or Equal To

Hints & tips

  • Comparison Operators let you compare!
Login to download
  • 00:04 In this video, I want to talk about comparison operators,
  • 00:08 Comparison Operators.
  • 00:12 And comparison operators allow you to do pretty much what they sound like.
  • 00:17 They allow you to compare two things together.
  • 00:19 Later on, we're going to do comparison statements where we can find the answers
  • 00:23 to questions, but in order to do those, we need comparison operators.
  • 00:27 And they're sort of like math operators.
  • 00:29 They're symbols that you can use.
  • 00:31 And they are equal to, not equal to,
  • 00:36 greater than, less than, greater than or
  • 00:43 equal to, and less than or equal to.
  • 00:49 You're probably familiar with these from back in grade school math.
  • 00:52 Greater than, less than allows you to compare two things.
  • 00:55 Is 5 greater than 2?
  • 00:59 Is 5 less than 2, right?
  • 01:02 Is 5 equal to2?
  • 01:03 So we haven't looked at variables yet, and so
  • 01:06 this double equal to sign may be a little weird to you.
  • 01:09 But in the next video, we'll talk about variables, and I'll explain why
  • 01:12 this is normal to have a double equal to sign, instead of just an equal to sign.
  • 01:16 But to determine if everything is equal to, we just do the double equal to signs.
  • 01:20 Here is one you may not be familiar with, not equal to, this exclamation point in
  • 01:25 almost every programming language usually means not, right?
  • 01:28 It's just sort of universal computer programming thing, not.
  • 01:32 So not equal to.
  • 01:34 So let's go ahead and run this.
  • 01:36 It's not going to do much at this point, we're just saying is 5 greater than 2?
  • 01:40 And I have a hunch that 5 is greater than 2.
  • 01:44 And when I run this, we get this true back.
  • 01:47 And true is a boolean, usually they're true or false.
  • 01:50 And later on when we do comparison statements, we're going to say,
  • 01:53 if this thing is true, then do this.
  • 01:55 If it's false, do that.
  • 01:56 Or if it's true, do this, else, do that.
  • 01:59 But for right now,
  • 02:00 you can just see it's just out putting on those screen true or false?
  • 02:04 Is 5 equal to 2?
  • 02:06 I don't think so, false.
  • 02:07 So those are comparison operators, a little bit abstract at this point.
  • 02:11 They'll become very useful later on, as we start to use comparison statements.
  • 02:15 And comparison statements are basically if, else statements.
  • 02:18 And they're like a cornerstone of all programming.
  • 02:20 You're going to use if, else, comparison statements all the time.
  • 02:24 And you'll use these operators in those statements.
  • 02:26 So equal to, not equal to, greater than, less than, greater than or equal to,
  • 02:30 you're probably familiar with this.
  • 02:32 If you don't exactly remember, it means is the number greater than or equal to?
  • 02:36 So if we went 5 greater than equal to 2, it is greater than or
  • 02:41 equal to, because it's greater than.
  • 02:45 It's not equal to, but it's greater than or equal to one or
  • 02:48 the other has to be true.
  • 02:49 So if we went to 6, 5 is not greater than or equal to 6 so that's false.
  • 02:57 If we want 5 greater than equal to 5, that's going to be true and the same for
  • 03:01 less than or equal to.
  • 03:03 Is it less than or equal to?
  • 03:05 So those are comparison operators.
  • 03:06 We'll use these a lot throughout the course and
  • 03:09 you'll use them forever in your computer programming.
  • 03:11 In the next video, we're going to talk about variables.

Lesson notes are only available for subscribers.

Floats and Integers
03m:20s
Variables
04m:04s
Share this lesson and earn rewards

Facebook Twitter LinkedIn WhatsApp Email

Gift this course
Give feedback

How is your GoSkills experience?

I need help

Your feedback has been sent

Thank you

Back to the top

© 2023 GoSkills Ltd. Skills for career advancement