IDL: foreach (制御ブロック)
foreach の要素の順をすぐに忘れてしまうのと、メモランダムに入れていると見つけにくいという理由で、ほんの短い記事ですが独立させました。
Documentation Center [Harris Geospatial Docs Center]
foreach elm, arr [, idx] do begin
endforeach
; elm: 配列 arr の要素, arr: 配列, idx 配列のインデックス
monthlist = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',$ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] dayofmonth = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] foreach monthname, monthlist, im do begin ; im is Index for Month if( im NE 1 ) then begin print, string( monthname + " has", dayofmonth[ im ], " days",$ format = '( a, i3, a )' ) endif else begin print, string( monthname + " has", dayofmonth[ im ], " or",$ dayofmonth[ im ] + 1, " days",$ format = '( a, i3, a, i3, a )' ) endelse endforeach; monthname, monthlist, im ; 結果 Jan has 31 days Feb has 28 or 29 days Mar has 31 days Apr has 30 days May has 31 days Jun has 30 days Jul has 31 days Aug has 31 days Sep has 30 days Oct has 31 days Nov has 30 days Dec has 31 days