C++,python,热爱算法和机器学习
全部博文(1214)
分类: Python/Ruby
2014-12-10 13:51:57
Method | Example Code | Output |
---|---|---|
For Loop |
<% for i in 0..9 %>
Result: <%= i %>, <% end %> |
Result: 0,1,2,3,4,5,6,7,8,9 |
<% @people = Person.find(:all) %>
<% for i in 0...@person.length %> Result: <%= @person[i].name %>, <% end %> |
Result: John,Peter,Sharon | |
<% @people = Person.find(:all) %>
<% for person in @people %> Result: <%= @person.name %>, <% end %> |
Result: John,Peter,Sharon | |
While Loop |
<% i = 0 %>
<% while( i < 10 ) %> Result: <%= i %>, <% i+= 1 %> <% end %> |
Result: 0,1,2,3,4,5,6,7,8,9 |
Do While Loop |
<% i = 5 %>
<% begin %> Result: <%= i %>, <% i+= 1 %> <% end while( i < 10 ) %> |
Result: 5,6,7,8,9 |
Switch Statement |
<% foo = 5 %>
<% case foo %> <% when 1 %> Foo is equal to 1 <% when 2..9 %> Foo is between 2 and 9 <% when 10 %> Foo is equal to 10 <% end %> |
Foo is between 2 and 9 |