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?

有帮助吗?

解决方案

while (true)
{
  // some code

  if (condition)
    break; // HERE

  // some other code
}

其他提示

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.
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top