Can not exit While Loop

Hi all, I have a code as attachment!
I want to exit while loop with condition “excel file have not data”, but after running to final row data, it cannot perform the next step (closed browser) (please see attactment)


Please help me!

Hi @loanptt3,

That is because you don’t have a condition to catch the final row. The loop assumes that there’s still a value to get on that 5th row. So in order to avoid that and exit on the 4th row you must have a condition to check the row number.

The error says that “Row index must be between 1…4” so 5 doesn’t count but the loop continues that’s why you get that error.

Try this code, this might help you.

while(findTestData('TestData'.getValue(1, row) != true) {
     if (row <= 4) {
          //your code here
     }
     else {
         break
     }
}

Hope that helps. . . :slight_smile:

Hi Arnel!
In still cannot do that, please help me again


Thanks!

Hi @loanptt3,

Could share the error message? Thanks

Hi Arnel!
Please see error message


Thank you!

Hi @loanptt3,

Try getting the rowNumbers. . .

while(findTestData('TestData'.getValue(1, row) != true) {
     if (row <= findTestData("TestData").getRowNumbers()) {
          //your code here
     }
     else {
         break
     }
}

Thank you for you support but my data number in data file don’t fixed! :’(

Can you explain that a little further? I don’t quite understand what are you trying to do.

I have a list of user that quantity are not constant. I want while loop stop when the row is null

Then do a null checker, something like:

while (your_condition) {
    if (findTestData("TestData").getValue(1, row) != null || 
        findTestData("TestData").getValue(1, row) == "") {
          //your code here
     }
     else {
         break
     }
}
1 Like