# Newb Question bout if/elseif

Page 1 of 1

## 3 Replies - 1178 Views - Last Post: 01 August 2016 - 03:52 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=395775&amp;s=3bff5e8ba260ec09c1cc08f7ca973e83&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 AmericanPi

Reputation: -5
• Posts: 14
• Joined: 30-July 16

# Newb Question bout if/elseif

Posted 30 July 2016 - 04:59 PM

Hey all! First Post!!

=begin
i can't debug this code.
i think i need to fix the way i'm taking and assigning the input.
or it could be the way im writing my if, elsif statements.
=end

puts "Enter Your Age : "

age = gets.to_i

if (age < 5)
puts "You are not old enough to take this survey."
else (age >= 5) || (age <= 6)
puts "You are in kindergarten."
elseif (age >= 6) && (age <=14)

elseif
puts "Gave it a shot"
end

Is This A Good Question/Topic? 0

## Replies To: Newb Question bout if/elseif

### #2 sepp2k

• D.I.C Lover

Reputation: 2511
• Posts: 3,988
• Joined: 21-June 11

## Re: Newb Question bout if/elseif

Posted 30 July 2016 - 05:36 PM

The keyword is spelled elsif. elseif is interpreted as the name of a method, that's why you get an exception about the method not existing when that part of the code is reached.

elsif takes a condition and else doesn't. So else (age >= 5) || (age <= 6) is interpreted as an unconditional else-block whose first statement is (age >= 5) || (age <= 6), which does nothing.

Note that once you fix that and (age >= 5) || (age <= 6) is interpreted as a condition, it will always be true because any age that's not >= 5 will necessarily be <= 6. So at least one of the two conditions will always be true.

### #3 AmericanPi

Reputation: -5
• Posts: 14
• Joined: 30-July 16

## Re: Newb Question bout if/elseif

Posted 01 August 2016 - 03:22 PM

GOT IT!!!

elsif (not spelled elseif) requires a condition.
else does not
elsif is the beef in my if burger (in this instance).

Thanks allot. I've been trying to finagle that for a few days.

here's my code.

puts "Enter Your Age : "

age = gets.to_i

if (age < 5)
puts "You are not old enough to take this survey."
elsif (age == 5) || (age == 6)
puts "You are in kindergarten."
elsif (age >= 7) && (age <= 13)
puts "you are in middlechool."
elsif (age >= 14) && (age <= 18)
puts "You are in High School."
else
puts "GO TO COLLEGE!!!!"
#i thought of doing this but it would be the same thing as the else i have at the end. and the else is much shorter so...
#elseif (age > 18)
#       puts "GO TO COLLEGE!!"

end

i get a path error on this pc.
Can you tell me if it's working?

### #4 AmericanPi

Reputation: -5
• Posts: 14
• Joined: 30-July 16

## Re: Newb Question bout if/elseif

Posted 01 August 2016 - 03:52 PM

Fixed all that path error stuff.
sorry to post so much...don't see how to edit my posts.
tx