Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8801671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:53:42+00:00 2026-06-14T00:53:42+00:00

There is an exercise in 6.00x edX whose answer’s suggestion provided by them is

  • 0

There is an exercise in 6.00x edX whose answer’s suggestion provided by them is as follows:

def genPrimes():
    primes = []   # primes generated so far
    last = 1      # last number tried
    while True:
        last += 1
        for p in primes:
            if last % p == 0:
                break
        else:
            primes.append(last)
            yield last

Looking to the identation I can clearly see that this ELSE is not related to the IF. I thought it was a bug but when I executed, the code was fine and I can’t understand what is happening, what does that ELSE does?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:53:43+00:00Added an answer on June 14, 2026 at 12:53 am

    else part of your for loop executes, when your for loop runs successfully without breaking in the middle of the iteration.

    So, in your example, : –

    if last % p == 0:
          break
    

    if your above if condition in for loop becomes true in some iteration, it will break out of your for loop, and in that case your else will not execute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was a exercise in my book, which asked me to write a for
Exercise: There's too much repetition in this file. Use strings, formats, and escapes to
There's a question on my exercise sheet to find the complement of r =
As an exercise in both writing Windows Services and communicating with them, I've decided
Simple beginner exercise: There's an input box where you put in your name seperated
In day 2 of the go tutorial there is this exercise: Why may it
In my Rails 3.2 application, there is an Exercise model with attributes muscle_group and
I am refreshing on algorithm theory (from Cormen). There is an exercise in the
I'm trying for exercise to do the following: there is an array of points,
It's an exercise of EF code-first. There's a simple method. I want to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.