Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add loop counter to foreach in csh

In CSH foreach loop or for loop, how can I add a loop iterator or counter which increases from 10 to 1000 with steps of 20?

Something like foreach i (1..20..5) or for (i=1;i<20;i++).

like image 696
SkypeMeSM Avatar asked Feb 22 '11 19:02

SkypeMeSM


2 Answers

If you have the seq command, you can use:

foreach i (`seq 1 5 20`)
  ... body ...
end

If you don't have seq, here is a version based on @csj's answer:

@ i = 1
while ($i <= 20)
  ... body ...
  @ i += 5
end
like image 130
Jeremiah Willcock Avatar answered Oct 23 '22 05:10

Jeremiah Willcock


Any documentation I've found online seems to indictate no for loop is available. However, the while loop can be used. I don't actually know csh, so the following is approximate based on what I read:

set i = 10
while ($i <= 1000)
    # commands...
    set i = $i + 20
end
like image 39
csj Avatar answered Oct 23 '22 05:10

csj