Kenyans247 Forum

Welcome, Guest: Join Kenyans247 LOGIN!

Stats: 224 Members, 11,371 topics and 65 posts Date: Sunday 05 April 2020 at 04:53 PM
TrendingRecentNewestClassifiedDirectoryLivescoresLive Kenyan TVLive Kenyan Radio

Ruby If, Else If Command Syntax

Kenyans247 / Science/Technology / Programing / Ruby If, Else If Command Syntax (18 View's)

Ruby If, Else If Command Syntax Ruby If, Else If Command Syntax
(Go Down) (» Reply topic)
Ruby If, Else If Command Syntax by Kenyans247(m): Sun 22, March, 2020 08:09am
The Ruby language has a very simple control structure that is easy to read and follow.

If syntax

if var == 10
print “Variable is 10”
end

If Else Syntax

if var == 10
print “Variable is 10”
else
print “Variable is something else”
end

If Else If Syntax

Here’s the key difference between Ruby and most other languages. Note that “else if” is actually spelled “elsif” without the e.

if var == 10
print “Variable is 10”
elsif var == “20”
print “Variable is 20”
else
print “Variable is something else”
end

Ternary (shortened if statement) Syntax

Ternary syntax is the same in Ruby as most languages. The following sample will print “The variable is 10” if var is equal to 10. Otherwise it will print “The variable is Not 10”.

print “The variable is ” + (var == 10 ? “10” : “Not 10”)

https://www.howtogeek.com/howto/programming/ruby/ruby-if-else-if-command-syntax/

(» Reply topic) (» Go Up)

Recommended for you

» Ruby If, Else If Command Syntax » Ruby If, Else If Command Syntax
Viewing this topic:
1 guest(s) viewing this topic

Sections: Properties, Diaspora, Politics, Family, Africa, Education, Programing, Computers, Art, Graphics & Video, Phones, Photography, Social Media/K247 Chit-Chat, Gaming, Celebrities, Literature, Somalia Forum, South Sudan Forum, Ugandan Forum, Rwanda Forum, Tanzania Forum,

Kenyans247 - Copyright © 2019 - 2020 Sande Kennedy. All rights reserved. See How To Advertise.
Disclaimer: Every Kenyans247 member is solely responsible for anything that he/she posts or uploads on Kenyans247.