Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Ruby If, Else If Command Syntax Rubīna Ja else if Komandas sintakse

The Ruby language has a very simple control structure that is easy to read and follow. Ruby valodā ir ļoti vienkārša kontroles struktūra, kas ir viegli lasīt un sekot.

If syntax Ja sintakse

if var == 10 ja var == 10
print “Variable is 10″ print "Mainīgais lielums ir 10"
end beigas

If Else Syntax Ja Else Sintakses

if var == 10 ja var == 10
print “Variable is 10″ print "Mainīgais lielums ir 10"
else citādi
print “Variable is something else” print "Mainīgais lielums ir kaut kas cits"
end beigas

If Else If Syntax Ja else if sintakse

Here's the key difference between Ruby and most other languages. Šeit ir būtiska atšķirība starp Ruby un lielākajā daļā citu valodu. Note that “else if” is actually spelled “elsif” without the e. Norāda, ka "cits, ja" tiešām ir rakstīts "elsif" bez e.

if var == 10 ja var == 10
print “Variable is 10″ print "Mainīgais lielums ir 10"
elsif var == “20″ elsif var == "20"
print “Variable is 20″ print "Mainīgais lielums ir 20"
else citādi
print “Variable is something else” print "Mainīgais lielums ir kaut kas cits"
end beigas

Ternary (shortened if statement) Syntax Trīskāršu (saīsināt, ja deklarācija) Sintakses

Ternary syntax is the same in Ruby as most languages. Trīskāršu sintakse ir Ruby tāpat kā lielākajā daļā valodu. The following sample will print “The variable is 10″ if var is equal to 10. Pēc parauga "print" mainīgais lielums ir 10 ", ja var ir vienāds ar 10. Otherwise it will print “The variable is Not 10″. Citādi tā būs print "mainīgais nav 10".

print “The variable is ” + (var == 10 ? “10″ : “Not 10″) print "mainīgais ir" + (var == 10? "10": "Nav 10")

This article was originally written on 10/31/09 Tagged with: Šis pants tika sākotnēji rakstīts uz 10/31/09 tagged with: Ruby Ruby

Daily Email Updates Daily Email Updates

You can get our how-to articles in your inbox each day for free. Jūs varat saņemt mūsu how-to rakstus savā pastkastītē katru dienu par brīvu. Just enter your name and email below: Vienkārši ievadiet jūsu vārdu un e-pasta zemāk:


Name: Vārds:
Email: E-pasts:

Our Friends Our Friends
Getting Started Getting Started


About How-To Geek Par How-To Geek
What Is That Process? Kas ir šis process?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. All Rights Reserved.