Ask a Question

While loop does not terminate when condition is met, continues

SOLVED
bgran05
Occasional Contributor

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!

2 REPLIES 2
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
Occasional Contributor

I see. Thank you. Marked as solution. 🙂

cancel
Showing results for 
Search instead for 
Did you mean: