Prime numbers print from range 2…100How do I call Objective-C code from Swift?Swift Beta performance: sorting arraysWhy Swift is 100 times slower than C in this image processing test?Swift: print() vs println() vs NSLog()Random array range 1-4 with each number only printed twiceUpdated to Xcode 7.1 (from 6.4) caused UIIMageView animation brokenAssigning Random numbers that don't repeat to the text in an array of labels SwiftHow to get the current day number in current month and yearSwift control flow counting with multiplesReturn substring from attributed string using range in Swift

What is the difference between "Grippe" and "Männergrippe"?

Changing JPEG to RAW to use on Lightroom?

Why can't you reverse the order of the input redirection operator for while loops?

What is Spectral Subtraction for noise reduction?

When, exactly, does the Rogue Scout get to use their Skirmisher ability?

Why is "-ber" the suffix of the last four months of the year?

Gambler coin problem: fair coin and two-headed coin

Can you grapple/shove when affected by the Crown of Madness spell?

What stops you from using fixed income in developing countries?

Talk interpreter

How should i charge 3 lithium ion batteries?

How long do you think advanced cybernetic implants would plausibly last?

If the Shillelagh cantrip is applied to a club with non-standard damage dice, what is the resulting damage dice?

Redacting URLs as an email-phishing preventative?

How would a low-tech device be able to alert its user?

Can I get a PhD for developing an educational software?

Does Yeshayahu 43:10b / 43:13a imply HaShem was created?

What to look for in a spotting scope?

Billiard balls collision

Where does learning new skills fit into Agile?

Is it legal for source code containing undefined behavior to crash the compiler?

How many birds in the bush?

How do I make my image comply with the requirements of this photography competition?

"There were either twelve sexes or none."



Prime numbers print from range 2…100


How do I call Objective-C code from Swift?Swift Beta performance: sorting arraysWhy Swift is 100 times slower than C in this image processing test?Swift: print() vs println() vs NSLog()Random array range 1-4 with each number only printed twiceUpdated to Xcode 7.1 (from 6.4) caused UIIMageView animation brokenAssigning Random numbers that don't repeat to the text in an array of labels SwiftHow to get the current day number in current month and yearSwift control flow counting with multiplesReturn substring from attributed string using range in Swift






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-3















I have been assigned with a task to print prime numbers from a range 2...100. I've managed to get most of the prime numbers but can't figure out how to get rid of 9 and 15, basically multiples of 3 and 5. Please give me your suggestion on how can I fix this.



for n in 2...20 
if n % 2 == 0 && n < 3
print(n)
else if n % 2 == 1
print(n)
else if n % 3 == 0 && n > 6




This what it prints so far:



2
3
5
7
9
11
13
15
17
19









share|improve this question


























  • You should google first. Check this out - en.wikipedia.org/wiki/Primality_test and en.wikipedia.org/wiki/Generating_primes

    – battlmonstr
    Mar 27 at 19:48







  • 3





    is this a homework for university? maybe try solving this by implementing Sieve of Eratosthenes. This algorithm will give you primes below N and if you are having trouble with that, feel free to ask again.

    – user3469811
    Mar 27 at 19:48







  • 2





    You need to handle n % 5 == 0 || n % 3 == 0 as well. You are also not guaranteeing that a number is not divisible by another prime, so your test might not give reliable results - search for Sieve of Eratosthenes.

    – jweyrich
    Mar 27 at 19:49







  • 1





    This is pretty well-travelled territory, especially now that Swift has been around for a bit. Have you taken a look at LeetCode solutions?

    – Adrian
    Mar 27 at 19:52











  • Have a look here codereview.stackexchange.com/questions/211437/…

    – ielyamani
    Mar 27 at 21:52

















-3















I have been assigned with a task to print prime numbers from a range 2...100. I've managed to get most of the prime numbers but can't figure out how to get rid of 9 and 15, basically multiples of 3 and 5. Please give me your suggestion on how can I fix this.



for n in 2...20 
if n % 2 == 0 && n < 3
print(n)
else if n % 2 == 1
print(n)
else if n % 3 == 0 && n > 6




This what it prints so far:



2
3
5
7
9
11
13
15
17
19









share|improve this question


























  • You should google first. Check this out - en.wikipedia.org/wiki/Primality_test and en.wikipedia.org/wiki/Generating_primes

    – battlmonstr
    Mar 27 at 19:48







  • 3





    is this a homework for university? maybe try solving this by implementing Sieve of Eratosthenes. This algorithm will give you primes below N and if you are having trouble with that, feel free to ask again.

    – user3469811
    Mar 27 at 19:48







  • 2





    You need to handle n % 5 == 0 || n % 3 == 0 as well. You are also not guaranteeing that a number is not divisible by another prime, so your test might not give reliable results - search for Sieve of Eratosthenes.

    – jweyrich
    Mar 27 at 19:49







  • 1





    This is pretty well-travelled territory, especially now that Swift has been around for a bit. Have you taken a look at LeetCode solutions?

    – Adrian
    Mar 27 at 19:52











  • Have a look here codereview.stackexchange.com/questions/211437/…

    – ielyamani
    Mar 27 at 21:52













-3












-3








-3








I have been assigned with a task to print prime numbers from a range 2...100. I've managed to get most of the prime numbers but can't figure out how to get rid of 9 and 15, basically multiples of 3 and 5. Please give me your suggestion on how can I fix this.



for n in 2...20 
if n % 2 == 0 && n < 3
print(n)
else if n % 2 == 1
print(n)
else if n % 3 == 0 && n > 6




This what it prints so far:



2
3
5
7
9
11
13
15
17
19









share|improve this question
















I have been assigned with a task to print prime numbers from a range 2...100. I've managed to get most of the prime numbers but can't figure out how to get rid of 9 and 15, basically multiples of 3 and 5. Please give me your suggestion on how can I fix this.



for n in 2...20 
if n % 2 == 0 && n < 3
print(n)
else if n % 2 == 1
print(n)
else if n % 3 == 0 && n > 6




This what it prints so far:



2
3
5
7
9
11
13
15
17
19






swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 19:44









rmaddy

259k29 gold badges351 silver badges416 bronze badges




259k29 gold badges351 silver badges416 bronze badges










asked Mar 27 at 19:41









Sergey SSergey S

12 bronze badges




12 bronze badges















  • You should google first. Check this out - en.wikipedia.org/wiki/Primality_test and en.wikipedia.org/wiki/Generating_primes

    – battlmonstr
    Mar 27 at 19:48







  • 3





    is this a homework for university? maybe try solving this by implementing Sieve of Eratosthenes. This algorithm will give you primes below N and if you are having trouble with that, feel free to ask again.

    – user3469811
    Mar 27 at 19:48







  • 2





    You need to handle n % 5 == 0 || n % 3 == 0 as well. You are also not guaranteeing that a number is not divisible by another prime, so your test might not give reliable results - search for Sieve of Eratosthenes.

    – jweyrich
    Mar 27 at 19:49







  • 1





    This is pretty well-travelled territory, especially now that Swift has been around for a bit. Have you taken a look at LeetCode solutions?

    – Adrian
    Mar 27 at 19:52











  • Have a look here codereview.stackexchange.com/questions/211437/…

    – ielyamani
    Mar 27 at 21:52

















  • You should google first. Check this out - en.wikipedia.org/wiki/Primality_test and en.wikipedia.org/wiki/Generating_primes

    – battlmonstr
    Mar 27 at 19:48







  • 3





    is this a homework for university? maybe try solving this by implementing Sieve of Eratosthenes. This algorithm will give you primes below N and if you are having trouble with that, feel free to ask again.

    – user3469811
    Mar 27 at 19:48







  • 2





    You need to handle n % 5 == 0 || n % 3 == 0 as well. You are also not guaranteeing that a number is not divisible by another prime, so your test might not give reliable results - search for Sieve of Eratosthenes.

    – jweyrich
    Mar 27 at 19:49







  • 1





    This is pretty well-travelled territory, especially now that Swift has been around for a bit. Have you taken a look at LeetCode solutions?

    – Adrian
    Mar 27 at 19:52











  • Have a look here codereview.stackexchange.com/questions/211437/…

    – ielyamani
    Mar 27 at 21:52
















You should google first. Check this out - en.wikipedia.org/wiki/Primality_test and en.wikipedia.org/wiki/Generating_primes

– battlmonstr
Mar 27 at 19:48






You should google first. Check this out - en.wikipedia.org/wiki/Primality_test and en.wikipedia.org/wiki/Generating_primes

– battlmonstr
Mar 27 at 19:48





3




3





is this a homework for university? maybe try solving this by implementing Sieve of Eratosthenes. This algorithm will give you primes below N and if you are having trouble with that, feel free to ask again.

– user3469811
Mar 27 at 19:48






is this a homework for university? maybe try solving this by implementing Sieve of Eratosthenes. This algorithm will give you primes below N and if you are having trouble with that, feel free to ask again.

– user3469811
Mar 27 at 19:48





2




2





You need to handle n % 5 == 0 || n % 3 == 0 as well. You are also not guaranteeing that a number is not divisible by another prime, so your test might not give reliable results - search for Sieve of Eratosthenes.

– jweyrich
Mar 27 at 19:49






You need to handle n % 5 == 0 || n % 3 == 0 as well. You are also not guaranteeing that a number is not divisible by another prime, so your test might not give reliable results - search for Sieve of Eratosthenes.

– jweyrich
Mar 27 at 19:49





1




1





This is pretty well-travelled territory, especially now that Swift has been around for a bit. Have you taken a look at LeetCode solutions?

– Adrian
Mar 27 at 19:52





This is pretty well-travelled territory, especially now that Swift has been around for a bit. Have you taken a look at LeetCode solutions?

– Adrian
Mar 27 at 19:52













Have a look here codereview.stackexchange.com/questions/211437/…

– ielyamani
Mar 27 at 21:52





Have a look here codereview.stackexchange.com/questions/211437/…

– ielyamani
Mar 27 at 21:52












3 Answers
3






active

oldest

votes


















4















Your "algorithm" is wrong. You should store somewhere your prime numbers and then just check if n satisfies the condition n % prime != 0 for each prime. If it does, just append this n to an array of primes and continue to next n.



Since Swift 4.2 you can use this very simple algorithm using allSatisfy



var primes = [Int]()

for n in 2...100
if primes.allSatisfy( n % $0 != 0 )
primes.append(n)



print(primes) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]


Or, you can implement more effective Sieve of Eratosthenes algorithm.



Below is my simple implementation (there are ofc more effective solutions)



var range = [Int](2...100)
var p = 0

while true
guard let newPrimeIndex = range.firstIndex(where: $0 > p ) else break
p = range[newPrimeIndex]
range.removeAll(where: $0 % p == 0 && $0 != p )


print(range) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]





share|improve this answer



























  • oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

    – Sergey S
    Mar 27 at 20:09


















0















Made for Swift 5



Unlike other answers, this is easily scaleable. I did not include a pre-made list of prime numbers, which would not work for very large numbers which have not been included.



Here is the algorithm I came up with. I made it as efficient as I can, with the factors only going up to the floor of the square root of the number. This reduces wasted time comparing factors which will never work.



import Foundation


// Function to determine whether a number is prime
func isPrime(_ num: Int) -> Bool
let max = Int(floor(sqrt(Double(num))))
guard max >= 2 else return true

for factor in 2...max
if num.isMultiple(of: factor) // Write num % factor == 0 for older versions of Swift
return false



return true



// Find if a number is prime for numbers 2 to 200
for i in 2...100
if isPrime(i)
print(i)







share|improve this answer




















  • 3





    For prime numbers in a large range a sieving method would scale better than this trial division method.

    – Martin R
    Mar 27 at 20:39



















-1















I finally figured it out lol, It might be not pretty but it works haha, Thanks for everyone's answer. I'll post what I came up with if maybe it will help anyone else.



for n in 2...100 
if n % 2 == 0 && n < 3
print(n)
else if n % 3 == 0 && n > 6
else if n % 5 == 0 && n > 5
else if n % 7 == 0 && n > 7
else if n % 2 == 1
print(n)







share|improve this answer



























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385273%2fprime-numbers-print-from-range-2-100%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4















    Your "algorithm" is wrong. You should store somewhere your prime numbers and then just check if n satisfies the condition n % prime != 0 for each prime. If it does, just append this n to an array of primes and continue to next n.



    Since Swift 4.2 you can use this very simple algorithm using allSatisfy



    var primes = [Int]()

    for n in 2...100
    if primes.allSatisfy( n % $0 != 0 )
    primes.append(n)



    print(primes) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]


    Or, you can implement more effective Sieve of Eratosthenes algorithm.



    Below is my simple implementation (there are ofc more effective solutions)



    var range = [Int](2...100)
    var p = 0

    while true
    guard let newPrimeIndex = range.firstIndex(where: $0 > p ) else break
    p = range[newPrimeIndex]
    range.removeAll(where: $0 % p == 0 && $0 != p )


    print(range) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]





    share|improve this answer



























    • oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

      – Sergey S
      Mar 27 at 20:09















    4















    Your "algorithm" is wrong. You should store somewhere your prime numbers and then just check if n satisfies the condition n % prime != 0 for each prime. If it does, just append this n to an array of primes and continue to next n.



    Since Swift 4.2 you can use this very simple algorithm using allSatisfy



    var primes = [Int]()

    for n in 2...100
    if primes.allSatisfy( n % $0 != 0 )
    primes.append(n)



    print(primes) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]


    Or, you can implement more effective Sieve of Eratosthenes algorithm.



    Below is my simple implementation (there are ofc more effective solutions)



    var range = [Int](2...100)
    var p = 0

    while true
    guard let newPrimeIndex = range.firstIndex(where: $0 > p ) else break
    p = range[newPrimeIndex]
    range.removeAll(where: $0 % p == 0 && $0 != p )


    print(range) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]





    share|improve this answer



























    • oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

      – Sergey S
      Mar 27 at 20:09













    4














    4










    4









    Your "algorithm" is wrong. You should store somewhere your prime numbers and then just check if n satisfies the condition n % prime != 0 for each prime. If it does, just append this n to an array of primes and continue to next n.



    Since Swift 4.2 you can use this very simple algorithm using allSatisfy



    var primes = [Int]()

    for n in 2...100
    if primes.allSatisfy( n % $0 != 0 )
    primes.append(n)



    print(primes) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]


    Or, you can implement more effective Sieve of Eratosthenes algorithm.



    Below is my simple implementation (there are ofc more effective solutions)



    var range = [Int](2...100)
    var p = 0

    while true
    guard let newPrimeIndex = range.firstIndex(where: $0 > p ) else break
    p = range[newPrimeIndex]
    range.removeAll(where: $0 % p == 0 && $0 != p )


    print(range) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]





    share|improve this answer















    Your "algorithm" is wrong. You should store somewhere your prime numbers and then just check if n satisfies the condition n % prime != 0 for each prime. If it does, just append this n to an array of primes and continue to next n.



    Since Swift 4.2 you can use this very simple algorithm using allSatisfy



    var primes = [Int]()

    for n in 2...100
    if primes.allSatisfy( n % $0 != 0 )
    primes.append(n)



    print(primes) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]


    Or, you can implement more effective Sieve of Eratosthenes algorithm.



    Below is my simple implementation (there are ofc more effective solutions)



    var range = [Int](2...100)
    var p = 0

    while true
    guard let newPrimeIndex = range.firstIndex(where: $0 > p ) else break
    p = range[newPrimeIndex]
    range.removeAll(where: $0 % p == 0 && $0 != p )


    print(range) // [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 28 at 10:50

























    answered Mar 27 at 19:51









    Robert DreslerRobert Dresler

    8,6762 gold badges9 silver badges28 bronze badges




    8,6762 gold badges9 silver badges28 bronze badges















    • oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

      – Sergey S
      Mar 27 at 20:09

















    • oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

      – Sergey S
      Mar 27 at 20:09
















    oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

    – Sergey S
    Mar 27 at 20:09





    oh man, this seems still complicated for my level, but maybe soon I will get it. Thanks!

    – Sergey S
    Mar 27 at 20:09













    0















    Made for Swift 5



    Unlike other answers, this is easily scaleable. I did not include a pre-made list of prime numbers, which would not work for very large numbers which have not been included.



    Here is the algorithm I came up with. I made it as efficient as I can, with the factors only going up to the floor of the square root of the number. This reduces wasted time comparing factors which will never work.



    import Foundation


    // Function to determine whether a number is prime
    func isPrime(_ num: Int) -> Bool
    let max = Int(floor(sqrt(Double(num))))
    guard max >= 2 else return true

    for factor in 2...max
    if num.isMultiple(of: factor) // Write num % factor == 0 for older versions of Swift
    return false



    return true



    // Find if a number is prime for numbers 2 to 200
    for i in 2...100
    if isPrime(i)
    print(i)







    share|improve this answer




















    • 3





      For prime numbers in a large range a sieving method would scale better than this trial division method.

      – Martin R
      Mar 27 at 20:39
















    0















    Made for Swift 5



    Unlike other answers, this is easily scaleable. I did not include a pre-made list of prime numbers, which would not work for very large numbers which have not been included.



    Here is the algorithm I came up with. I made it as efficient as I can, with the factors only going up to the floor of the square root of the number. This reduces wasted time comparing factors which will never work.



    import Foundation


    // Function to determine whether a number is prime
    func isPrime(_ num: Int) -> Bool
    let max = Int(floor(sqrt(Double(num))))
    guard max >= 2 else return true

    for factor in 2...max
    if num.isMultiple(of: factor) // Write num % factor == 0 for older versions of Swift
    return false



    return true



    // Find if a number is prime for numbers 2 to 200
    for i in 2...100
    if isPrime(i)
    print(i)







    share|improve this answer




















    • 3





      For prime numbers in a large range a sieving method would scale better than this trial division method.

      – Martin R
      Mar 27 at 20:39














    0














    0










    0









    Made for Swift 5



    Unlike other answers, this is easily scaleable. I did not include a pre-made list of prime numbers, which would not work for very large numbers which have not been included.



    Here is the algorithm I came up with. I made it as efficient as I can, with the factors only going up to the floor of the square root of the number. This reduces wasted time comparing factors which will never work.



    import Foundation


    // Function to determine whether a number is prime
    func isPrime(_ num: Int) -> Bool
    let max = Int(floor(sqrt(Double(num))))
    guard max >= 2 else return true

    for factor in 2...max
    if num.isMultiple(of: factor) // Write num % factor == 0 for older versions of Swift
    return false



    return true



    // Find if a number is prime for numbers 2 to 200
    for i in 2...100
    if isPrime(i)
    print(i)







    share|improve this answer













    Made for Swift 5



    Unlike other answers, this is easily scaleable. I did not include a pre-made list of prime numbers, which would not work for very large numbers which have not been included.



    Here is the algorithm I came up with. I made it as efficient as I can, with the factors only going up to the floor of the square root of the number. This reduces wasted time comparing factors which will never work.



    import Foundation


    // Function to determine whether a number is prime
    func isPrime(_ num: Int) -> Bool
    let max = Int(floor(sqrt(Double(num))))
    guard max >= 2 else return true

    for factor in 2...max
    if num.isMultiple(of: factor) // Write num % factor == 0 for older versions of Swift
    return false



    return true



    // Find if a number is prime for numbers 2 to 200
    for i in 2...100
    if isPrime(i)
    print(i)








    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 27 at 20:35









    George_EGeorge_E

    1,6172 gold badges10 silver badges29 bronze badges




    1,6172 gold badges10 silver badges29 bronze badges










    • 3





      For prime numbers in a large range a sieving method would scale better than this trial division method.

      – Martin R
      Mar 27 at 20:39













    • 3





      For prime numbers in a large range a sieving method would scale better than this trial division method.

      – Martin R
      Mar 27 at 20:39








    3




    3





    For prime numbers in a large range a sieving method would scale better than this trial division method.

    – Martin R
    Mar 27 at 20:39






    For prime numbers in a large range a sieving method would scale better than this trial division method.

    – Martin R
    Mar 27 at 20:39












    -1















    I finally figured it out lol, It might be not pretty but it works haha, Thanks for everyone's answer. I'll post what I came up with if maybe it will help anyone else.



    for n in 2...100 
    if n % 2 == 0 && n < 3
    print(n)
    else if n % 3 == 0 && n > 6
    else if n % 5 == 0 && n > 5
    else if n % 7 == 0 && n > 7
    else if n % 2 == 1
    print(n)







    share|improve this answer





























      -1















      I finally figured it out lol, It might be not pretty but it works haha, Thanks for everyone's answer. I'll post what I came up with if maybe it will help anyone else.



      for n in 2...100 
      if n % 2 == 0 && n < 3
      print(n)
      else if n % 3 == 0 && n > 6
      else if n % 5 == 0 && n > 5
      else if n % 7 == 0 && n > 7
      else if n % 2 == 1
      print(n)







      share|improve this answer



























        -1














        -1










        -1









        I finally figured it out lol, It might be not pretty but it works haha, Thanks for everyone's answer. I'll post what I came up with if maybe it will help anyone else.



        for n in 2...100 
        if n % 2 == 0 && n < 3
        print(n)
        else if n % 3 == 0 && n > 6
        else if n % 5 == 0 && n > 5
        else if n % 7 == 0 && n > 7
        else if n % 2 == 1
        print(n)







        share|improve this answer













        I finally figured it out lol, It might be not pretty but it works haha, Thanks for everyone's answer. I'll post what I came up with if maybe it will help anyone else.



        for n in 2...100 
        if n % 2 == 0 && n < 3
        print(n)
        else if n % 3 == 0 && n > 6
        else if n % 5 == 0 && n > 5
        else if n % 7 == 0 && n > 7
        else if n % 2 == 1
        print(n)








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 20:07









        Sergey SSergey S

        12 bronze badges




        12 bronze badges






























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385273%2fprime-numbers-print-from-range-2-100%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해