In this program, You will learn how to print all prime numbers between 1 to n in JavaScript.

```
while(Condition){
//Statement
Increment/Decrement
}
```

## Example: How to print all prime numbers between 1 to n

```
let n = parseInt(prompt("Enter a number:"));
for (j = 2; j <= n; j++) {
let p = 1;
let i = 2;
while (i < j) {
if (parseInt(j % i) == 0) {
p = 0;
break;
}
i++;
}
if (p == 1) {
console.log("Number is prime:" + j);
}
}
```

#### Output:

```
Enter a number:> 50
Number is prime:2
Number is prime:3
Number is prime:5
Number is prime:7
Number is prime:11
Number is prime:13
Number is prime:17
Number is prime:19
Number is prime:23
Number is prime:29
Number is prime:31
Number is prime:37
Number is prime:41
Number is prime:43
Number is prime:47
```