Control Flow Flashcards
What is control flow?
Control flow is that we can select different outcomes depending on the environment and the input.
What is an if statement?
Ruby takes an if statement and decides if its true and runs code accordingly.
What is an else statement?
The else statement is the continuation of the if statement. This code runs after the if statement is false.
What is an elsif statement?
An elsif statement gives the if else statement more options.
What is an unless statement?
An if statement checks if something is true, An unless statement checks if something is false and runs code accordingly.
What is a comparator?
A comparator checks if two values are equal or not
we use == to check if they are equal and != if we want to check if two values are not equal.
What are the comparator for less or equal than?
less than <
less than or equal to <=
greater than >
Greater than or equal to >=
What are boolean operators?
Boolean operators are either true or false
- && (and)
- | | (or)
- ! (not)
What is an and operator?
- && (and), The expression is true if both statements before and after && are true
true && true => true
true && false => false
false && true => false
false && false => false
What is an Or-operator?
- | | (or) is an operator when at least one of the expressions are true true || true # => true true || false # => true false || true # => true false || false # => false
What is an Not-operator?
A not operator (!) makes any statement after the expression false
!true= false
What is gets.chomp?
Gets chomp is for getting user input from the terminal
What is the .downcase method?
the .downcase method takes the user input and converts it do lower case letters.
What is the .include? method
The include? method checks if the user input contains what we want
What is the .gsub! method?
The .gsub method stands for global substitution and changes all the chosen inputs.
string_to_change.gsub!(/s/, “th”)