Loops and iterators Flashcards

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

What is a While loop?

A

While something is true the code will run, there is a danger of infinite loops in these cases, make sure to add a increment.
Ex i= i+1

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

What is the each loop?

A

The each loop is an iterator

that goes through an object and executes the code on each single object.

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

What is the one line each iterator?

A

arr.each { | x | do_something x }

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

What is the syntax for the each iterator?

A

arr.each do |x|
do_something x
end

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

What are nested iterators?

A

nested iterators are used when you want to extract and operate on hashes and arrays with multiple objects.

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

What is the select method in ruby?

A

The select method is a method that automatically iterates through a collection and retrieves the value you want.

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

How do you use the select method in ruby?

A
There are three ways to use the select method in ruby:
- something.select do	|x|
 some_code 
end”
- something.select { |x| x.some_code}
- something.select(&:some_code)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly