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 790561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:42:11+00:00 2026-05-14T21:42:11+00:00

I am a beginner with Python and trying few programs. I have something like

  • 0

I am a beginner with Python and trying few programs. I have something like the following WHILE loop construct in Python (not exact).

IDLE 2.6.4      
>>> a=0
>>> b=0
>>> while a < 4:
      a=a+1
      while b < 4:
         b=b+1
         print a, b

  
1 1
1 2
1 3
1 4

I am expecting the outer loop to loop through 1,2,3 and 4. And I know I can do this with FOR loop like this

>>> for a in range(1,5):
       for b in range(1,5):
           print a,b

  
1 1
1 2
.. ..
.. .. // Other lines omitted for brevity
4 4

But, what is wrong with WHILE loop? I guess I am missing some thing obvious, but could not make out.

Answer:
The corrected WHILE loop..

>>> a=0
>>> while a < 4:
    a=a+1
    b=0
    while b<4:
        b=b+1
        print a,b

        
1 1
.. ..
.. .. // Other lines omitted for brevity
4 4

P.S: Searched out SO, found few questions but none as close to this. Don’t know whether this could classified as homework, the actual program was different, the problem is what puzzles me.

  • 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-05-14T21:42:12+00:00Added an answer on May 14, 2026 at 9:42 pm

    You’re not resetting b to 0 right inside your outer loop, so b stays at the value it had after the first leg of the outer loop — 4 — and the inner loop never executes again.

    The for loops work fine because they do reset their loop control variables correctly; with the less-structured while loops, such resetting is in your hands, and you’re not doing it.

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

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Look for Spy++ May 17, 2026 at 12:19 am
  • Editorial Team
    Editorial Team added an answer These kinds of tags[footnote] are hardwired; and pretty much only… May 17, 2026 at 12:19 am
  • Editorial Team
    Editorial Team added an answer No, both a servlet and a filter: are instantiated (once)… May 17, 2026 at 12:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm a beginner in python and I'm trying to use a octal number in
I'm trying to get simple code working, unfortunately I'm a python beginner. My script
I'm trying to make a 4x4 sudoku solver in Python (I'm only a beginner!)
I have the following XML document that I have to parse using python's minidom:
First, let me say that I'm a complete beginner at Python. I've never learned
Python beginner here, so I apologize if this question has a simple answer. (I
First things first, I am a Python beginner, with a typical C++/Java background for
As a complete beginner with no programming experience, I am trying to find beautiful
Sorry for the beginner python question, but I cant find anywhere how to do
I'm trying to write a simple GTD-style todo list app with python and gtk

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.