2. Iterators: Conditional Looping “while” allows us to loop through code while a set condition is true x = 1 while x < 10 puts x.to_s + “ iteration” x += 1 end
3. Times 5.times { puts “hello” } 5.times { |num| puts “hi”+num.to_s} 99.times do |beer_num| puts "#{beer_num} bottles of beer” end 99.times do puts "some bottles of beer” end
4. Creating a new array x = [1, 2, 3, 4] => [1, 2, 3, 4] x = %w(1 2 3 4) => [“1”, “2”, “3”, “4”] chef = Array.new(3, “bork”) => [“bork”, “bork”, bork”]
5 is an object that is an instance of the integer classtimes is a method of the 5 objecttimes is a method on an object that is an instance of integer
Alot of the time you will be using an array when you iterate over somethingAn array is just a list of items.Every spot in the list acts like a variable and you can make each spot point to a different objectW means wordsArray is a class, needs to start with capital letter
IRBif you go off the array it will be nil
join is cool because it makes a string for youshovel operatormultidimensional array
Does anyone know what a hash is? associative array collection of key-value pairskeys can be numbers or strings Difference from an Array
merge takes the value from the second hashmerge! changes h1
you would think that delete should need a bang to change the hash, but delete doesn’t exist with a bangdelete returns the value