Q:

Checking for prime number - C# logic

Here is a snippet from my code. Basically once the button is clicked this logic should fire out and determine if the number is prime or not. The problem is that some numbers are returning as "not prime", when in reality they are. Can anyone point out where the flaw is?
Thank you
    private void bntTestPrime_Click(object sender, EventArgs e)
    {
        int num;
        double num_sqrt;
        int num_fl;

        num = Convert.ToInt32(txtInput.Text);

        num_sqrt = Math.Sqrt(num);

        num_fl = Convert.ToInt32(Math.Floor(num_sqrt));

        for (int i = 1; i <= num_fl; i++)
        {
            if (num % i == 0 && i != num)
                lblResult_prime.Text = "Number " + num + " is not Prime.";
            else
                lblResult_prime.Text = "Number " + num + " is Prime.";
        }

    }

A:

To add to Blender's answer, I'd like to point out that you're simply setting the output text on every iteration loop. That means your result will only depend upon the last number checked. What you need to do is assume the number is prime and loop through until a divisor is found. If a divisor is found. The number is prime if and only if no divisors are found. In the end the code should look something like this:
private bool IsPrime(int num)
{
    double num_sqrt = Math.Sqrt(num);
    int num_fl = Convert.ToInt32(Math.Floor(num_sqrt));

    for (int i = 2; i <= num_fl; i++)
    {
        if (num % i == 0)
        {
            return false;
       }
    }
    return true;
}

private void bntTestPrime_Click(object sender, EventArgs e)
{
    int num = Convert.ToInt32(txtInput.Text);
    bool isPrime = IsPrime(num);
    if (isPrime)
        lblResult_prime.Text = "Number " + num + " is Prime.";
    else
        lblResult_prime.Text = "Number " + num + " is not Prime.";
}

