title: Ruby if else in array.each
body: <p>New to Ruby here.  I am attempting to put an if else statement in an array to send a string if a certain modulus == 0.  for the life of me i can't find it anywhere.  I am sure someone will find it ridiculously simple.</p>
  
  <pre><code>a = *(1..100)
  a.each { |i| puts "three" if i % 3 == 0 elsif puts "five" if i % 5 == 0 else puts i}
  </code></pre>
  
  <p>Just not sure of the correct syntax.  Still new to ruby and am trying to learn the syntax.  Took a C class last semester and my brain keeps wanting to put in C syntax. </p>
  
  <p>When I leave it as</p>
  
  <pre><code>a = *(1..100)
  a.each { |i| puts "three" if i % 3 == 0}
  </code></pre>
  
  <p>it works fine, just trying to figure out how to add if else to it.  Help is appreciated.</p>
  
  <p>The answers below were really helpful.  I am trying to take it a step further and call it into a function.  It keeps returning 5, and not "five", or 3, and not "three".</p>
  
  <p>here is my function:</p>
  
  <pre><code>def array_mod
  a = *(1..100)
  a.each { |i| if i % 3 == 0  &amp;&amp; i % 5 == 0; i = "fifteen" elsif i % 3 == 0; i = "three" elsif i % 5 == 0; i = "five" else i = i end }
  </code></pre>
  
  <p>end</p>
  
  <p>and here is my attempt at calling it.</p>
  
  <pre><code>require "minitest/autorun"
  require_relative "array_modulus.rb"
  
  
  
  class TestArrayFunction &lt; Minitest::Test
  
  
  def test_array1
  
      results = array_mod
  
      assert_equal(100, results.length)
  end
  
  def test_array2
  
      results = array_mod
      assert_equal("three", results[2])
  end
  
  
  end
  </code></pre>
  
  <p>I was told it is not updating my array.  Thanks again.</p>