# Problem with while loop in included script

**URL:** <https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224>\
**Category:** URScript\
**Created:** [September 10, 2016, 5:06pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224 "2016-09-10T17:06:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon43982785](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon43982785](https://forum.universal-robots.com/u/anon43982785)\
**Post date:** [September 10, 2016, 5:06pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224/1 "2016-09-10T17:06:25Z")

</div>

Working with URSim version 3.3.2.266 (Sep 05)  
I’m having a problem with subroutines that include a while loop in a program. (I haven’t tried other kinds of loops)

A simple program that shows the problem is:

![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/0cb6f78606c6a59bda149ec46b6d42d1494e5a0c.png)

The offending subroutine script is:

![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/c0d615699c58d9484dc45143c33eb21df1086d19.png)

The saved full offending script is:

 ![](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/7db7ec1c81ece87c22b561d9fc9ae26b91c81ad5.png)

If I comment out the “while” and “end” lines the script works fine -so the problem seems to be with them.

Can you see anything I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![anon43982785](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon43982785](https://forum.universal-robots.com/u/anon43982785)\
**Post date:** [September 10, 2016, 11:41pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224/2 "2016-09-10T23:41:19Z")

</div>

I’m having similar problems with “if” clauses.

---

<div class="post-metadata">

**Author:** ![anon93510157](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@anon93510157](https://forum.universal-robots.com/u/anon93510157)\
**Post date:** [September 15, 2016, 3:33pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224/3 "2016-09-15T15:33:23Z")

</div>

Is it possible that theSubProgram file is a .script file? It has to be a .urp file.

---

<div class="post-metadata">

**Author:** ![anon43982785](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon43982785](https://forum.universal-robots.com/u/anon43982785)\
**Post date:** [September 15, 2016, 3:48pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224/4 "2016-09-15T15:48:15Z")

</div>

Yes it is a script file.

Am I misunderstanding the The URScript Programming Language manual (Version 3.2 April 15, 2016 page 4)?

That seems to show that “while” and “if” clauses are part of the script language…

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [September 15, 2016, 3:56pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224/5 "2016-09-15T15:56:33Z")

</div>

`if`and `while`statements are fully a part of the URScript language.  
But @anon93510157 is right that is has to be a .urp file when included as a subprogram.

---

<div class="post-metadata">

**Author:** ![anon43982785](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon43982785](https://forum.universal-robots.com/u/anon43982785)\
**Post date:** [September 15, 2016, 4:19pm UTC](https://forum.universal-robots.com/t/problem-with-while-loop-in-included-script/224/6 "2016-09-15T16:19:44Z")

</div>

@anon93510157 @jbm

Thanks, somehow I missed that.
