# Test Case While Loop

**URL:** <https://forum.robotframework.org/t/test-case-while-loop/6592>\
**Category:** Robot Framework\
**Created:** [27 December 2023 17:00 UTC](https://forum.robotframework.org/t/test-case-while-loop/6592 "2023-12-27T17:00:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CSUThornton](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/csuthornton/32/3270_2.png) [@CSUThornton](https://forum.robotframework.org/u/CSUThornton)\
**Post date:** [27 December 2023 17:00 UTC](https://forum.robotframework.org/t/test-case-while-loop/6592/1 "2023-12-27T17:00:38Z")

</div>

Is it possible to write a test case where the entire test case is a while loop and the condition of the while loop is

while test.status == failed  
Run this test  
Generate a test result  
end while

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [28 December 2023 00:08 UTC](https://forum.robotframework.org/t/test-case-while-loop/6592/2 "2023-12-28T00:08:37Z")

</div>

Hi @CSUThornton,

By default once a test fails it exits, so your while would never be true.

It’s not clear what you are trying to acheive, perhaps if you describe the problem you’re trying to solve here we can suggest some better ways to acheive what you want.

Having said that, if you put `Run this test` and `Generate a test result` into a keyword and call it with [Wait Until Keyword Succeeds](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Wait%20Until%20Keyword%20Succeeds) you’d have something similar to what you described. Bearing in mind if any keyword in `Run this test` fails `Generate a test result` won’t be run.

Builtin library also has other keywords that might be useful like:

- [Run Keyword And Continue On Failure](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Continue%20On%20Failure)
- [Run Keyword And Expect Error](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Expect%20Error)
- [Run Keyword And Ignore Error](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Ignore%20Error)
- [Run Keyword And Return Status](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Return%20Status)
- [Run Keyword And Warn On Failure](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Warn%20On%20Failure)
- [Run Keyword Unless](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20Unless)

It really depends on what your trying to do as to what the best option is.

Hope that helps,

Dave.

---

<div class="post-metadata">

**Author:** ![CSUThornton](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/csuthornton/32/3270_2.png) [@CSUThornton](https://forum.robotframework.org/u/CSUThornton)\
**Post date:** [28 December 2023 17:39 UTC](https://forum.robotframework.org/t/test-case-while-loop/6592/5 "2023-12-28T17:39:08Z")

</div>

This is what I’m trying to do:

```
MUST support NAT6to4 Device
   [Documentation] Check translations
   [Tags] 00000000001
   BuiltIn.Sleep 5 seconds
   SSH to host ${SRVR} ${USER} ${PASS}
   WRITE ping6 -c 20 -s 1500 1:1:1::1 -I ens224
   ${output} get_config ${connection_en} ${TRANSLATIONS}
   Log ${output}
   ${status} = nat_check ${6to4NAT_IP1} ${6to4NAT_IP2} ${6to4NAT_IP3} ${6to4NAT_IP4} ${output}
   Should be Equal ${status} ${TRUE}
   IF ${status} == ${TRUE}
       SET SUITE VARIABLE ${NAT6to4_result} 1
   END
   WHILE True ${NAT6to4_result} = 0
       BuiltIn.Sleep 5 seconds
       SSH to host ${SRVR} ${USER} ${PASS}
       WRITE ping6 -c 20 -s 1500 1:1:1::1 -I ens224
       ${output} get_config ${connection_en} ${TRANSLATIONS}
       Log ${output}
       ${status} = nat_check ${6to4NAT_IP1} ${6to4NAT_IP2} ${6to4NAT_IP3} ${6to4NAT_IP4} ${output}
       Should be Equal ${status} ${TRUE}
       IF ${status} == ${TRUE}
           SET SUITE VARIABLE ${NAT6to4_result} 1
       END
   END
   Log To Console \n\nIPv6_Dest_result equals: ${NAT6to4_result}
   ${output} get_config ${connection_en} ${CLEAR_TRANSLATIONS}
   BuiltIn.Sleep 5 seconds
   ${output} = Run sudo route del -net 2.2.2.0 netmask 255.0.0.0
   ${output} = Run sudo route -6 del 1:1:1::/64
   ${result1} = Run route
   Should Not Contain ${result1} 2.2.2.0
   ${result2} = Run route -6
   Should Not Match Regexp ${result2} ${IPV6ROUTE}
   Close SSH
   BuiltIn.Sleep 30 seconds
   Close connection
   BuiltIn.Sleep 30 seconds

```

The problem is that Robot keeps coming back with:

```
------------------------------------------------------------------------------
MUST support NAT6to4 Device :: Check translations | FAIL |
'While' is a reserved keyword.
------------------------------------------------------------------------------

```

I’m following the syntax provided in the following link:

[[While loops in Robot Framework | Robocorp documentation](https://robocorp.com/docs/languages-and-frameworks/robot-framework/while-loops)](I’m following the syntax provided in the following link: [While loops in Robot Framework | Robocorp documentation](https://robocorp.com/docs/languages-and-frameworks/robot-framework/while-loops) I’m not sure what the issue is.)

I’m not sure what the issue is.

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [28 December 2023 19:20 UTC](https://forum.robotframework.org/t/test-case-while-loop/6592/6 "2023-12-28T19:20:08Z")

</div>

Yeah your using the WHILE loop wrong, the second argument is a optional one that is “limit” and by default it has a limit of 10000, the first which happens to be “True” in your test means it will never evaluate to anything else, but this will be where you’d evaluate for it to exit or not, I’d imagine you’d be wanting to check if ${NAT6to4\_result} is equal 0 here based on what you’ve provided.

Please be aware an exception will be thrown when using a limit if the condition is never met (limit is met)so you’d want to handle it.

Hope that helps

Thanks

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [28 December 2023 19:25 UTC](https://forum.robotframework.org/t/test-case-while-loop/6592/7 "2023-12-28T19:25:55Z")

</div>

Sorry in addition and I wouldn’t recommend it, If you really wanted to loop infinitely, you can set the `limit` argument to `NONE`, but I’d recommend setting appropriately based on your understanding of the application.

You’d want to wrap in a try catch to capture the exception as well if the limit is met.
