How it break the loop if count is not fixed

I want to handle an Computer vision automation where loop count is not fixed. For some case the count is 3 for some count is 7 likewise. So, what condition need to apply in while loop to handle this type of situation? Please refer to attached screenshot.


in the image if you see there are 3 lines for some case there are 5 or 7 line I want to use while loop but what condition need to apply

Hi @Neha_Aggarwal1
Below is a sample workflow with while loop you may refer for.

# Get the OCR text from the image
ocrText = GetOCRText(image)

# Get the number of iterations required
numIterations = ocrText.Length

# Initialize a counter
counter = 0

# Use a while loop
While counter < numIterations
    # Perform your automation logic here

    # Increment the counter
    counter = counter + 1
End While

Hi @Neha_Aggarwal1 ,

Can you explain further what are we trying to do with the example? Are we just counting the rows?

Kind regards,
Kenneth

Hi,
I can see in the first column there is a value. you can do one thing in the while loop’s body that, if column_value = “” that means blank or null then break.

2 Likes

Hey

Basically we have the same option as the normal activities, you can use the CV Extract Table Activity, it will returns the entire datatable, then you can just use the dt.RowCount to return the max iterations or just loop through the datatable

Regards

@kennbalobalo @Shanmathi


As u see in the image, I have to first click on First blue line then capture the yellow area by cv get text likewise I need to come in second line and capture the text in the box.
this steps i did perfectly but the main difficulty I am facing is now here there are 3-line description for some case there are 5 or 7 lines so how to handle that in loop what condition need to apply.

Hy @Neha_Aggarwal1

bool moreLines = true

while (moreLines)
{
    // Capture the text of the current line using the "CV Get Text" activity
    // Check if there is a next line
    // If there is a next line, continue the loop
    // If there is no next line, set moreLines to false to exit the loop
}

In this example, the loop continues as long as the moreLines variable is set to true . Each iteration of the loop captures the text of the next line, and checks if there is a subsequent line. If there is no next line, the value of moreLines is set to false to exit the loop.

@fernando_zuluaga @Kalpesh_Chaudhari @Shanmathi @kennbalobalo please look into this situation too and help me for same .To handle above case i am automating like this show in UiPath screeshot.


counter =counter +1

Hi Neha,

Why is there a need of counter <=2? as you are checking it dynamically it only should be true and once internal condition is false then break it on the basis of if the value is null then use break activity.

2 Likes

@Shanmathi how to check if there is next line?

@fernando_zuluaga cv extract table activity is not working here because this box is not detecting as in table format

use do while , if the next line is empty then go to next step

dont forget to put counter inside the while to increment the get text
image

string currentLine = readLine();

if (currentLine == null)
{
    // There is no next line
}
else
{
    // There is a next line
}

To check if there is a next line, you can use a method that returns a Boolean indicating if there is a next line or not. The exact method would depend on the language and environment you are using, but a common method in many programming languages is to use the readLine() method which returns a string of the next line, or null if there is no next line. You can then check if the result is null to determine if there is a next line.