Please tell me what mistake I have done, Print Primes from 1 to N. If possible tell only by using while loop as I am beginner

#include
using namespace std;
int main() {
int n;
int r = 3;
cin>>n;
int i;
cout<<2<<endl;
while(i<n){
int i = 2;
if (r%i!=0)
{
while(r%i!=0,i<n){
cout<<r<<endl;
i = i + 1; }

}
r = r + 1;

}

return 0;

}

hello @yashratnani6 you can do this by using while loop but as the test cases are larger thats why you woldnt be able to submit with the while loop.
you have to do this by sieve of eratosthenes.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.