Control Flow Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is control flow?

A

Control flow is that we can select different outcomes depending on the environment and the input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an if statement?

A

Ruby takes an if statement and decides if its true and runs code accordingly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an else statement?

A

The else statement is the continuation of the if statement. This code runs after the if statement is false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an elsif statement?

A

An elsif statement gives the if else statement more options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an unless statement?

A

An if statement checks if something is true, An unless statement checks if something is false and runs code accordingly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a comparator?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the comparator for less or equal than?

A

less than <

less than or equal to <=

greater than >

Greater than or equal to >=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are boolean operators?

A

Boolean operators are either true or false

  • && (and)
  • | | (or)
  • ! (not)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an and operator?

A
  • && (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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an Or-operator?

A
- | | (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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Not-operator?

A

A not operator (!) makes any statement after the expression false
!true= false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is gets.chomp?

A

Gets chomp is for getting user input from the terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the .downcase method?

A

the .downcase method takes the user input and converts it do lower case letters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the .include? method

A

The include? method checks if the user input contains what we want

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the .gsub! method?

A

The .gsub method stands for global substitution and changes all the chosen inputs.

string_to_change.gsub!(/s/, “th”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is string interpolation ?

A

String interpolation adds a value to a string.

print “Adios, #{my_string}!”

17
Q

What is a While loop?

A

The while loop runs code as long as the conditions are true.

counter = 1
while counter < 11
  puts counter
  counter = counter + 1
end
18
Q

What is an infinite loop?

A

An infinite loop is a loop that runs forever.

They need to be avoided at all cost.

19
Q

What is an untill loop?

A

An until loop runs as long as the conditions are not met.

i = 0
until i == 6
  i = i + 1
end
puts i
20
Q

What is an assignment operator?

A

An assignment operator is used to update a variable.

+=, -=, *=, and /=.

21
Q

What is an for loop?

A

The for loop runs a code between a range.

for current_iteration_number in 1..100 do
puts “Hello world, this is number #{current_iteration_number}”
end

22
Q

What is an inclusive range?

A

An inclusive range is a range that includes the last number in the range
1..3 (two dots)

for num in 1..20 (don’t forget the in)
puts num
end

23
Q

What is an exclusive range?

A

An exclusive range is a range where the last number is not included in the range.

1..3 (three dots)

for num in 1…20 (don’t forget the in)
puts num
end

24
Q

What is an iterator?

A

An iterator is just a Ruby method that repeatedly invokes a block of code.

25
Q

What is the next keyword?

A

The next keyword is used to skip a step.

26
Q

What is an array?

A

An array is a variable with multiple items in it
my_array = [1, 2, 3, 4]
An array is also indexed starting from 0.

27
Q

How do you get user input?

A

gets.chomp

28
Q

What is The .each Iterator ?

A

.each method, which can apply an expression to each element of an object, one at a time.

object.each do | item | 
  # Do something 
end
29
Q

What is the .times Iterator?

A

The .times method is like a super compact for loop: it can perform a task on each item in an object a specified number of times

10.times { print “Chunky bacon!” }

30
Q

What is the .split Method?

A

it takes in a string and returns an array. If we pass it a bit of text in parentheses, .split will divide the string wherever it sees that bit of text, called a delimiter. For example,

text.split(“,”)