To find all the prime numbers less than or equal to 30, proceed as follows:
First generate a list of integers from 2 to 30:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Starting from 4, count up by 2 and cross out these numbers in the list:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
The first number in the list after 2 is 3; count up by 3 from 9 and cross out these numbers too:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
The first number not yet crossed out in the list after 3 is 5; proceed by counting up by 5 from 25:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Next number in the list after 5 that is not crossed out is 7, but 7
squared is 49 which is greater than 30 so the process is finished. The
numbers left not crossed out in the list are all the prime numbers less
than or equal to 30:
2 3 5 7 11 13 17 19 23 29