|
setup diary |
R | julia | ruby | python3 | |
if | a<-3 if(a==1){cat(1) }else if(a==2){cat(2) }else{cat(3)} | a=3 if a==1 print(1) elseif a==2 print(2) else print(3) end | a=3 if a==1 then p 1 elsif a==2 then p 2 else p 3 end | a=3 if a==1:print(1) elif a==2:print(2) else:print(3) |
三項演算子 | a<-2 cat(ifelse(a>0,"+","-")) | a=2 print(a>0 ? "+" : "-") | a=2 print(a>0?"+":"-") | a=2 print('+' if a>0 else '-') |
switch | i<-"a" cat(switch(i,a=1,b=2)) | i="a" p case i when "a" then 1 when "b" then 2 end | ||
for | for(i in 1:10){cat(i);cat("\n")} | for i=1:10 println(i) end | for i in 1..10 do p i end | for i in range(1,11):print(i) |
while | i<-0 while(i<10){cat(i<-i+1);cat("\n")} | let i=0 while i<10 println(i+=1) end end | i=0 while i<10 do p i+=1 end | i=0 while i<10:i+=1;print(i) |
無限ループ | repeat{cat(1);cat("\n")} | while true println(1) end | loop{p 1} | while True:print(1) |
ループを抜ける | break | break | break | break |
次のループ | next | continue | continue | next |
例外処理 | tryCatch(cat("1"/0), error=function(e)cat(-1)) | try print("1"/0) catch print(-1) end | begin p "1"/0 rescue p -1 end | try:print("1"/0) except:print(-1) |
終了処理 | tryCatch({cat(1);cat("\n")}, finally=cat(2)) | try println(1) finally println(2) end | begin p 1 ensure p 2 end | try:print(1) finally:print(2) |
複文 | a<-{cat(1);2} | a=(print(1);2) | a=(p 1;2) |