Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4394974
  • 博文数量: 1214
  • 博客积分: 13195
  • 博客等级: 上将
  • 技术积分: 9105
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-19 14:41
个人简介

C++,python,热爱算法和机器学习

文章分类

全部博文(1214)

文章存档

2021年(13)

2020年(49)

2019年(14)

2018年(27)

2017年(69)

2016年(100)

2015年(106)

2014年(240)

2013年(5)

2012年(193)

2011年(155)

2010年(93)

2009年(62)

2008年(51)

2007年(37)

分类: Python/Ruby

2014-12-10 13:51:57

来源:http://programming-tut.blogspot.jp/2009/10/ruby-on-rails-for-loop.html
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
阅读(1417) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~