# WHILE LOOP CONDITION CHECK

**URL:** <https://community.unix.com/t/while-loop-condition-check/255929>\
**Category:** Shell Programming and Scripting\
**Created:** [December 16, 2009, 4:48am UTC](https://community.unix.com/t/while-loop-condition-check/255929 "2009-12-16T04:48:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dashing201](https://community.unix.com/user_avatar/community.unix.com/dashing201/32/5589_2.png) [@dashing201](https://community.unix.com/u/dashing201)\
**Post date:** [December 16, 2009, 4:48am UTC](https://community.unix.com/t/while-loop-condition-check/255929/1 "2009-12-16T04:48:58Z")

</div>

Hello

I want to compare values of two variables as CHECK condition in a while loop.

eg:

```nohighlight
var1=0 
var2=10   
while [$var1 < $var2] 
do   
    echo " $var1 "
    var1=`expr $var1 + 1`
done

```

However this is giving error.How to do it in a proper manner?

Thanks.

---

<div class="post-metadata">

**Author:** ![Scott](https://community.unix.com/letter_avatar/scott/32/5_5575768a8748004e209b776fc1b2916d.png) [@Scott](https://community.unix.com/u/Scott)\
**Post date:** [December 16, 2009, 4:53am UTC](https://community.unix.com/t/while-loop-condition-check/255929/2 "2009-12-16T04:53:19Z")

</div>

```nohighlight
while [$var1 -lt $var2]

```

"\<" is used for redirection

---

<div class="post-metadata">

**Author:** ![dashing201](https://community.unix.com/user_avatar/community.unix.com/dashing201/32/5589_2.png) [@dashing201](https://community.unix.com/u/dashing201)\
**Post date:** [December 16, 2009, 5:07am UTC](https://community.unix.com/t/while-loop-condition-check/255929/3 "2009-12-16T05:07:19Z")

</div>

Thanks Buddy...  
I was trying it on CYGWIN. it was giving some error.However I tried it on unix , it is working fine.

KUDOS:b:

---

<div class="post-metadata">

**Author:** ![ichigo](https://community.unix.com/user_avatar/community.unix.com/ichigo/32/1750_2.png) [@ichigo](https://community.unix.com/u/ichigo)\
**Post date:** [December 16, 2009, 5:31am UTC](https://community.unix.com/t/while-loop-condition-check/255929/4 "2009-12-16T05:31:49Z")

</div>

```nohighlight
var1=0
var2=10
gawk -v v1="$var1" -v v2="$var2" 'BEGIN{
    while(v1 < v2){
        print v1
        v1++
    }
} '

```
