Forum Discussion

bgran05's avatar
bgran05
Occasional Contributor
7 years ago
Solved

While loop does not terminate when condition is met, continues

Hi,

 

I am running  a keyword test with a while loop. I made a minimal instance of a while loop that should terminate when project variable testResult = Fail. Initially, the variable testResult = Pass.

 

The test runs once, which is good, but I would expect it to not show the messages, "Don't run this if test has failed.", "Or this.", since those occur after the condition was met. I would think it would stop after testResult was set to "Fail".

 

Why are those Log Messages appearing in the log from the test run? 

 

Thanks!

  • In while loop the condition evaluate at the beginning.

    So the first run your conditions (testResult )is pass so it runs in to loop.

    in side loop you set it to fail.

    even condition(testResult ) set it to fail loop is active since no evaluation done.

     

    in second run it evaluate testResult = fails so it dose not go into the loop.

     

    if need to terminate loop immediately you have to have if condition in the loop to brake it.  

2 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    In while loop the condition evaluate at the beginning.

    So the first run your conditions (testResult )is pass so it runs in to loop.

    in side loop you set it to fail.

    even condition(testResult ) set it to fail loop is active since no evaluation done.

     

    in second run it evaluate testResult = fails so it dose not go into the loop.

     

    if need to terminate loop immediately you have to have if condition in the loop to brake it.  

    • bgran05's avatar
      bgran05
      Occasional Contributor

      I see. Thank you. Marked as solution. :)