## Issue

I’m just learning Ruby ðŸ™‚ and Im trying to create a simple prime-number program where *all* the primes of a number are printed.

I’m getting errors where the *prime and nonprime numbers are mixed up*

(ie: input of 9 will get you all nonprimes).

I’m sorry for such a beginner question – I’m struggling alot and need some help ðŸ™‚

```
puts "Enter a number please "
num = gets.chomp.to_i
i = 2
number = 2
while i < num
if number % i == 0
prime = false
end
i += 1
end
if prime == true
puts "#{number} is prime"
else
puts "#{number} is not prime"
end
number += 1
end
```

## Solution

```
while i < num
if number % i == 0
prime = false
end
i += 1
end
# ...
```

It looks like that first `end`

is meant to be an `else`

.

It’s easier to catch these things when you simplify your code, e.g. this method reduces to this (although there are other issues with it):

```
i = 2
number = 2
while i < num
(number % i).zero? ? prime = false : i += 1
puts "#{number} is #{'not ' unless prime}prime"
number += 1
end
```

Answered By – Mori

Answer Checked By – Dawn Plyler (BugsFixing Volunteer)