Optimizing nested loops

In a Workflow for guessing a random number, i have used a while loop (guessing loop) to keep asking the input until the random number and input match.

For the input, i hav added a try catch which is surrounded in a do while loop with condition that the exception message is none, so that the input in one iteration of guessing loop is kept on asked until no exceptions are found.

I wanted to know if there is any other way to do the above to task instead of using nested loops or to perform a more optimized method.

@Quenton_Wayne_Rebello

Welcome to the community

  1. Get a random number
  2. While loop with condition as true
  3. Inside loop input dialog box to ask for number
  4. After that if condition to check if it is correct or wrong…if correct use break …if wrong do nothing…it will ask again as loop runs again
  5. If you want to give maximum n chances in while loop you have max iteration option give a number to it

Hope this helps

Cheers

HI,

What purpose is inner loop and try-catch?
If the try-catch is only for checking if input value is numeric, we can check it in advance using Int32.TryParse method etc.

The following is a sample for it.

Sample20230531-2L.zip (2.9 KB)

Regards,

Thank you for the solution

The inner loop is used to ask the user to re enter the input when an exception occurs. The Try Catch is used for checking number is numeric and if its not null

Thank you for Your Solution

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.