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 Nếu Ruby, khac Nếu Cú pháp lệnh

The Ruby language has a very simple control structure that is easy to read and follow. Ruby ngôn ngữ có cấu trúc điều khiển rất đơn giản là dễ đọc và dễ làm theo.

If syntax Nếu cú pháp

if var == 10 nếu var == 10
print “Variable is 10″ print "biến là 10"
end cuối

If Else Syntax Nếu cú pháp khác

if var == 10 nếu var == 10
print “Variable is 10″ print "biến là 10"
else khác
print “Variable is something else” print "Variable là cái gì khác"
end cuối

If Else If Syntax Nếu khác Nếu Cú pháp

Here's the key difference between Ruby and most other languages. Đây là sự khác biệt chính giữa Ruby và các ngôn ngữ khác nhất. Note that “else if” is actually spelled “elsif” without the e. Lưu ý rằng "if" là thực sự đánh vần "elsif" mà không có e.

if var == 10 nếu var == 10
print “Variable is 10″ print "biến là 10"
elsif var == “20″ elsif var == "20"
print “Variable is 20″ print "biến là 20"
else khác
print “Variable is something else” print "Variable là cái gì khác"
end cuối

Ternary (shortened if statement) Syntax Ternary (nếu tuyên bố rút ngắn) Cú pháp

Ternary syntax is the same in Ruby as most languages. Ternary cú pháp là như nhau trong Ruby như hầu hết các ngôn ngữ. The following sample will print “The variable is 10″ if var is equal to 10. Các mẫu sau đây sẽ in "biến là 10" nếu var bằng 10. Otherwise it will print “The variable is Not 10″. Nếu không thì nó sẽ in "Không biến là 10".

print “The variable is ” + (var == 10 ? “10″ : “Not 10″) biến in "là" + (var == 10 "10":? "Không 10")

This article was originally written on 10/31/09 Tagged with: Bài viết này ban đầu được viết ngày 10/31/09 Tagged với: Ruby Ruby

Daily Email Updates Email cập nhật hàng ngày

You can get our how-to articles in your inbox each day for free. Bạn có thể làm thế nào chúng tôi vào các bài viết trong hộp thư của bạn mỗi ngày miễn phí. Just enter your name and email below: Chỉ cần nhập tên và email của bạn dưới đây:


Name: Tên:
Email: Email:

Leave a Comment Để lại một Thảo luận




Leave your Để lại của bạn friendly thân thiện comment here. bình luận ở đây.

If you have a computer help question, Nếu bạn có một câu hỏi giúp máy tính, click here to leave it on the forums bấm vào đây để lại nó trên các diễn đàn instead. thay vì.

Note: Your comment may not show up immediately on the site. Lưu ý: Ý kiến của bạn có thể không hiển thị ngay lập tức trên trang web.

Our Friends Bạn bè của chúng tôi
Getting Started Bắt đầu


About How-To Geek Giới How-To Geek
What Is That Process? Quá trình đó là gì?
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. Bản quyền © 2006-2009 HowToGeek.com. All Rights Reserved. Tất cả các quyền.