Question

In my application I have a mysql db table with many numerical records. I am doing some computations to these records. I would like to perform this computation in a loop with a ending condition. I was thinking about do-while loop, but I have scenario like this:

LOOP: {
    LOOP for computing euklidian distances between chosen records
    // HERE I WOULD LIKE TO CHCECK IF MY ENDING CONDITION IS TRUE. 
    // IF YES, WHOLE LOOP WILL END, AND IF NO, IT WILL CONTINUE
    LOOP for updating table records according to euklidian distances.
}

Can anyone help me please?

Was it helpful?

Solution

while (true)
{
  // some code

  if (condition)
    break; // HERE

  // some other code
}

OTHER TIPS

I think you can solve that with a simple endless loop and break:

while (true)
{
    // do computation
    if (/* check condition */)
        break;
    // update DB
}

Then the loop will run until the condition is met. You may should also ensure that this will not turn into an endless loop...

"Foreach" loop may be better for you to use for computing for each record from the table.

foreach(var record in listOfRecords)
{
    //LOOP for computing euklidian distances between chosen records

    if(condition)
    {
        break;
    }

    //LOOP for updating table records according to euklidian distances.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top