puts "如果使用break终止当前循环 " i = 0 ["Perl", "Python", "Ruby", "Scheme"].each do |lang| i += 1 if i == 3 break end p [i,lang] end puts "跳到下一个循环next:" i = 0 ["Perl", "Python", "Ruby", "Scheme"].each do |lang| i += 1 if i == 3 next end p [i,lang] end puts "redo是再执行一次上边的跳过下面的:" i = 0 ["Perl", "Python", "Ruby", "Scheme"].each do |lang| i += 1 if i == 3 redo end p [i,lang] end exit =begin 第一次应该是1,perl. 2,python 第二次应该是1,perl 2,python, 第三次应该是1,perl 2,python, 4,scheme 然额,实际却是 [1, "Perl"] [2, "Python"] [1, "Perl"] [2, "Python"] [4, "Scheme"] [1, "Perl"] [2, "Python"] [4, "Ruby"] [5, "Scheme"] =end
3.JPG (55.88 KB, 下载次数: 22)
xg1.JPG (13.77 KB, 下载次数: 20)
xg3.JPG (15.14 KB, 下载次数: 19)
捕获.JPG (53.48 KB, 下载次数: 18)
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |