条件循环

时间:2011-01-17 20:08:14

标签: c#

        static bool BoxDiscovery(h) {
            ...
            //I've acquired bmp by this point in the ellipses above 

            for (int v = 211; v < 661; v++) {
                Color c = bmp.GetPixel(h, v);
                if (c.R > 221 && c.G < 153)
                //if c.r > 221 && c.G < 153 get me out of this crazy
                //  thing Jane and return true, else false without the
                //  compiler throwing an 'Unreachable code detected'. 
                //  Use break or anything you want.
                ...
                }
            }
        }

我今天感觉特别愚蠢。

1 个答案:

答案 0 :(得分:5)

static bool BoxDiscovery(h) 
{
    for (int v = 211; v < 661; v++) 
    {
        Color c = bmp.GetPixel(h, v);
        if (c.R > 221 && c.G < 153)
        {
            return true;
        }
    }
    // Make sure you provide a default value here
    // If we reach this point your condition hasn't been 
    // satisfied meaning that no box has been found
    // so you can safely return false
    return false;
}