different symbols and functions Flashcards
Define % and what it’s used for
% is a module used to find how many times a number can go into another. fro example 4 % 2 = 0 and 5 % 2 = 1.
Define ! and how it’s used
The symbol ! is = to “not”
For example num != 0 or num is not equal to 0.
or
if (num % 3) == 0 && !(num % 5 == 0)
Define ==
== is when you want to know if 2 variables are the same.
for example if num = 32
num == 32 then this is true
but
if
num == 22 then this is false
Define <=
less than or equal to
Define >=
Greater or equal to
Define >
Greater then
Define <
Less then
Define [] and what its used for
It gets the index in an array
For example
num[“hello”, “no”, “yes”]
num[2] would equal to “yes”
Define .length
.length is used to get the length of a string or and array
Define .chr
.chr is equal to a character of a string
Define i
i is used to define a number
i = 0
what are the Booleans in Ruby
in Ruby there are 2 Boolean values, true and false
How does an ‘if’ statement work?
if statement executes code if the Boolean is equal to ‘true’
Define def and return
def defines a method and return exits a method
Define elsif statement and what it does
elsif is a conditional statement that pairs with a previous if statement, it takes on a Boolean expression if the previous was false, for it to run the Boolean expression now has to be true.