Please do check what wrong in my code i hope everything right .. but on console its just displaying one single value o/p i.e 13 .. after i press enter key its displaying next prime upon each pres .. y it is going n like this ...
using System;
using System.Collections.Generic;
using System. Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main()
{
for (int i = 3; i < 50;i++ )
{
if (i % 2 == 0)
continue ;
if (i % 3 == 0)
continue;
if (i % 5 == 0)
continue;
if (i % 7 == 0)
continue;
if (i % 11 == 0)
continue;
Console.WriteLine(i);
}
}
}
}

VulpesPosted Jul 13, 2013, 12:32 PM
The output is now:
VulpesPosted Jul 13, 2013, 2:18 PM
You could also express it like this and get rid of the continue:
SUNIL GUTTAPosted Jul 13, 2013, 2:04 PM
Well can you say this above mentioned snippet is normalized to the codes we done(i.e mentioned in this post) till now .. just a clarification ... can it be still optimized ??
Ty for your help
Vulpes my go to man any-time
VulpesPosted Jul 13, 2013, 1:50 PM
If i is divisible by 2 then the for loop continues to the next value.
If i is divisible by 3, 5 or 7 (but not 3,5 or 7 themselves) then the for loop continues to the next value.
What's left must be prime and so is printed to the console.
SUNIL GUTTAPosted Jul 13, 2013, 1:41 PM
Well i tried using debugging i.e to check flow of code :)
actually problem is while executing when staring IF condition is satisfied i.e if(i%2) then it is going to continue then to for loop .. but the same flow is not same in case of second if statement i.e if(i%3) its not going on to continue when lets say i=9 . instead it going further for checking if conditions which are not necessary:)
Note: when i used curly braces for each continue .. debugging working fine .. ..
Why is issue ???
VulpesPosted Jul 13, 2013, 12:38 PM
because the cases 22, 33 and 44 will be picked up as multiples of 2,3 and 2 respectively.