Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

for loop

Status
Not open for further replies.

byuen

Programmer
May 14, 2003
6
US
for a korn shell, what is the equivalent c++ command for:

(for int i = 0; i < 20; i++) ?

thanks,
 
Yes, but I do not think it is what you wish. Here is a good Korn shell overview site:

for foo in $(ls);do
if [[ -d $foo ]];then
print &quot;$foo is a directory&quot;
else
print &quot;$foo is not a directory&quot;
fi
done

But, if you need a counter then do this:
count=99
while [[ $count -gt 0 ]];do
print &quot;\$count is $count&quot;
(( count -= 1 ))
done
 
This works...
Code:
   #!/bin/ksh

   CTR=21  # Needs to be one more than the number of times you want

   while (( CTR -= 1 ))
   do
      print &quot;Counter CTR is ${CTR}&quot;
   done
Of course this starts at 20 and counts down, but it does give you a loop that executes just that many times.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top