If inside loop and Else outside loop

I want to check a number for prime or not.I tried with loop but I could not print It is prime. I could only print if it is not prime. Also can we use If inside a loop and else outside the loop?How?
#include
using namespace std;
int main() {
//Prime Checker
//The number should not be divisible by 2,3,…N

int i = 2;
int N;
cin>>N;
while(i<N-1){
if(N%i==0){
cout<<“It is not prime”<<endl;
break;
}
i = i + 1;
}
else {
cout<<“It is a Prime”<<endl;
}
return 0;

Please save your code on ide.codingblocks.com and then share its link. I will make the changes in it.

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.