Separate the loops instead of nesting them. Putting one inside of the other makes the entire child loop run for each instance of the parent loop. (Hence the name.)
// (shared variables here)
foreach (KeyValuePair<string, int> total in totalOrders)
{
// Code relevant to all orders here
}
foreach (KeyValuePair<string, int> error in errorOrders)
{
// Code relevant to erroneous orders only here
}
If the loops need to share variables, declare these before the first loop. Variables created inside a loop will be local and stop existing when their loop is finished.