Click here to Skip to main content
15,900,110 members
Home / Discussions / C#
   

C#

 
AnswerRe: DataGridView and Deleting Rows Pin
Luc Pattyn10-May-10 2:32
sitebuilderLuc Pattyn10-May-10 2:32 
Questionsort by Pin
tanzeel8510-May-10 2:02
tanzeel8510-May-10 2:02 
AnswerRe: sort by Pin
Henry Minute10-May-10 5:27
Henry Minute10-May-10 5:27 
GeneralRe: sort by Pin
tanzeel8513-May-10 1:11
tanzeel8513-May-10 1:11 
AnswerRe: sort by Pin
Peace ON10-May-10 20:12
Peace ON10-May-10 20:12 
Questionreturn type error "not all code paths return a value" Pin
wjbjnr10-May-10 0:42
wjbjnr10-May-10 0:42 
AnswerRe: return type error "not all code paths return a value" Pin
nagendrathecoder10-May-10 0:53
nagendrathecoder10-May-10 0:53 
AnswerRe: return type error "not all code paths return a value" [modified] Pin
Pete O'Hanlon10-May-10 0:57
mvePete O'Hanlon10-May-10 0:57 
I'll reformat your code so that we can read it:

using System;

class one
{
  public int a;
  int f;

  public bool e(int i)
  {
    for (f = 2; f <= i; f++)
    {
      if (i % f == 0)
      {
        return false;
      }
      else
      {
        return true;
      }
    }
  }
}

class control
{
    public static void Main()
    {
      one obj = new one();
      Console.WriteLine("ENTER THE NUMBER TO BE CHECKED(SHOULD BE GREATER THAN 2)");
      int o=obj.a = int.Parse(Console.ReadLine());
      obj.e(o);
      if (obj.e(o))
        Console.WriteLine("THE VALUE IS PRIME");
      else
        Console.WriteLine("THE VALUE IS NOT PRIME");
    }
}
First of all, why f++ is unreachable. In your code, the for loop will always exit after the first run through - there is no way for it not to. Remove the return true to outside the loop and you'll solve both parts of your problem - the loop condition will be reachable and the code will return a value from all parts.

[Edit]I just want to point out that you need to code for an edge case here. What happens if I put 0 in as a value? The code will never enter the loop and will incorrectly report out that it's a prime number. You should add a check in here to ensure that it's not less than 2 and return the value accordingly.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



modified on Monday, May 10, 2010 7:27 AM

QuestionRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 4:31
wjbjnr10-May-10 4:31 
AnswerRe: return type error "not all code paths return a value" Pin
Alan N10-May-10 5:38
Alan N10-May-10 5:38 
AnswerRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 1:02
Som Shekhar10-May-10 1:02 
QuestionRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 5:25
wjbjnr10-May-10 5:25 
AnswerRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 5:35
Som Shekhar10-May-10 5:35 
GeneralRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 6:15
wjbjnr10-May-10 6:15 
GeneralRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 6:48
Som Shekhar10-May-10 6:48 
QuestionRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 7:59
wjbjnr10-May-10 7:59 
AnswerRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 8:03
Som Shekhar10-May-10 8:03 
GeneralRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 8:43
wjbjnr10-May-10 8:43 
GeneralRe: return type error "not all code paths return a value" Pin
Som Shekhar10-May-10 8:59
Som Shekhar10-May-10 8:59 
GeneralRe: return type error "not all code paths return a value" Pin
OriginalGriff10-May-10 9:03
mveOriginalGriff10-May-10 9:03 
GeneralRe: return type error "not all code paths return a value" Pin
wjbjnr10-May-10 9:51
wjbjnr10-May-10 9:51 
QuestionListBox.DisplayName problem Pin
reza assar10-May-10 0:29
reza assar10-May-10 0:29 
AnswerRe: ListBox.DisplayName problem Pin
Heinzzy10-May-10 0:47
Heinzzy10-May-10 0:47 
GeneralRe: ListBox.DisplayName problem Pin
reza assar11-May-10 1:56
reza assar11-May-10 1:56 
Questioncreating a setup in c#.net Pin
prasadbuddhika9-May-10 23:36
prasadbuddhika9-May-10 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.