Forum Discussion

sameerjade's avatar
sameerjade
Frequent Contributor
7 years ago
Solved

While loop in TestComplete

Hello All,

 

I am trying to use a while loop within a function in a TestComplete test item. When I run my test, it seems to be ignoring my while loop not executing it. Following is the code snippet:

 

while (i < 3) {
MyObjectName.Click();
i++;
}

 

If I have just the following, it works perfectly fine. Am I am missing something?

MyObjectName.Click();

 

Thank you,

 

Sameer

  • How are you initializing the variable i?  At that point in the while loop, it is checking that value first... if i is > or = to three, you'll never enter the loop.

     

    What I would do is the following:

    var i = 0;
    while (i < 3) {
    MyObjectName.Click();
    i++;
    }

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    How are you initializing the variable i?  At that point in the while loop, it is checking that value first... if i is > or = to three, you'll never enter the loop.

     

    What I would do is the following:

    var i = 0;
    while (i < 3) {
    MyObjectName.Click();
    i++;
    }
    • sameerjade's avatar
      sameerjade
      Frequent Contributor

      Thanks Robert. My bad, I initialized the variable using == instead of =

      It is now working. 

       

      -Sameer