problem in While and for loop

problem in While and for loop

Post by Nasi » Tue, 28 Aug 2001 06:51:43



Asslam-0-alaikum
I created  a script that uses a while loop and it did it's work ,but
ne thing lef that when I tried to  loop it until the there is some
key press(any).is there any way to it,
Second How I create an infinit  for loop or  in another for just say
that if want to loop from 2 19,then instead of writing
for i in 2 3 4 5 6 7 8 ....19,
I want a shortcut like
for i in [2-19]
 but it did not worked
Would there be solution,If any one have
pleaz............................

Nasir Mahmood
Lahore Pakistan

 
 
 

problem in While and for loop

Post by Ingo Blechschmid » Tue, 28 Aug 2001 17:30:13



> Asslam-0-alaikum
> Second How I create an infinit  for loop or  in another for just say
> that if want to loop from 2 19,then instead of writing
> for i in 2 3 4 5 6 7 8 ....19,
> I want a shortcut like
> for i in [2-19]
>  but it did not worked
> Would there be solution,If any one have

Type
for i in `seq 2 19`
That works fine...

bye,
      Ingo Blechschmidt

--


Time sharing - the use of many people by the computer.

 
 
 

problem in While and for loop

Post by Stephane Chazel » Tue, 28 Aug 2001 18:03:18


[...]

Quote:>> for i in 2 3 4 5 6 7 8 ....19,
>> I want a shortcut like
>> for i in [2-19]
[...]
> for i in `seq 2 19`
> That works fine...

But seq is present on very few systems

You could do
for i in `yes | sed -ne '2,19!d;=;19q'`

But the common and best way is to use a while loop:

i=2; while [ $i -lte 19 ]; do
  ...
  let 'i = i + 1' # won't work with Bourne sh
                  # i=`expr $i + 1`
done

Or with ksh93, zsh and recent bashs:

for (( i = 2; i <= 19; i++ ))

--
Stphane

 
 
 

problem in While and for loop

Post by Irwan Iskanda » Tue, 28 Aug 2001 11:20:23


#! /bin/ksh

x=2

while [ $x -le 19 ]
do
   echo $x
   x=`expr $x + 1`

done

cingkleung


> Asslam-0-alaikum
> I created  a script that uses a while loop and it did it's work ,but
> ne thing lef that when I tried to  loop it until the there is some
> key press(any).is there any way to it,
> Second How I create an infinit  for loop or  in another for just say
> that if want to loop from 2 19,then instead of writing
> for i in 2 3 4 5 6 7 8 ....19,
> I want a shortcut like
> for i in [2-19]
>  but it did not worked
> Would there be solution,If any one have
> pleaz............................

> Nasir Mahmood
> Lahore Pakistan

 
 
 

1. Press Ctrl-D whiling inputting

I write a program:

#include <stdio.h>
main()
{
   char str[81];
   while(1)
   {
      gets(str);
      printf("You input: %s\n",str);
   }

My question is why it causes infinitely loop after I press Ctrl-D.
Is there any solution about this?  Thanks.

--
     +------------------------------------------------------------+
    / \   Trying to maintain a good friendship with all people   / \
   /   + - - - - - - - - - - - - - - - - - - - - - - - - - - - -/ - +


+------------------------------------------------------------+   /
 \ /Home Page: http://susis.ust.hk/~enoch                     \ /
  +------------------------------------------------------------+

2. GNU C(1.36) under AIX

3. Matrox Mystique ands X.

4. Help -- Xf86 resolution problems

5. supraexpress modems (28.8) problems w/dial-ins

6. Running FreeBSD from a Jaz drive.

7. Netscape plug-ins problem

8. Help! Intel Etherexpress ISA/5x86

9. Problems with dialing out when dial-ins are enabled

10. Netscape 4.51 and plug-ins problem

11. looping on couplets in for loop?

12. break one loop and skip one iteration of outer loop

13. Stuck in a loop, stuck in a loop, ...