For Loop vs While Loop differences PYTHON
Question: I am a beginner to Python, and my professor does poor job explaining the
differences between loops. I wanted to ask this community the differences
between For loops and While loops. I looked at various resources but what I am
confused about is how for loops have no counter to bring them back to the
beginning like while loops: I have the following code written in for() loop
but my goal is to change it to a while loop. The code is not what is important
is how to change this code to a While() loop.

    
    
    for r_ow in range(Height_box):
        for c_col in range(Width_box):
            gridpoint = box * row + column
            if gridpoint in gridList:
                box[r_ow][c_col] = "Inside Box"
            else:
                outsideBox = (CurrentBox(boxWidth,Boxedge))
                ctr = 0
                for Box_edges in Box:
                    if eval(Box(boxWidth,boxHeight,box_edges,box_point)):
                        if box_edge in gridList:
                            ctr += 1
                Bow[r_ow][c_col] = str(int(box[r_ow][c_col]) + ctr)
    

So far, I have gotten to a point where I think this is what it suppose to look
like but now i get stuck in a CMD infinite loop.

    
    
    row = 0
    while r_ow < boxHeight:
        column = 0
        while c_col < boxWidth:
            gridpoint = box * row + column
            if gridpoint in gridList:
                box[r_ow][c_ol] = "Inside Box"
            else:
                outsideBox = (CurrentBox(boxWidth,Boxedge))
                ctr = 0
                while ctr < Boxes: 
                    if eval(Box(boxWidth,boxHeight,box_edges,box_point)):
                        if box_edge in gridList:
                        ctr += 1
            Bow[r_ow][c_col] = str(int(box[r_ow][c_col]) + ctr)
        column += 1
    row += 1
    return box  
    

Can anyone give some advice as to how to format the first code into while
loops()?

thank you very much!!


Answer: Your column increment statement (column += 1) is outside the corresponding
while loop.

Same for the row increment statement.

Right now, column will increment after the loop is done. But, you need it to
increment after every iteration of the loop.

Add a level of intend to both these statements and you are good to go.

    
    
            Box[r_ow][c_colu] = str(int(box[r_ow][c_col]) + ctr)
            column += 1
        row += 1
    return board    
    

Also there is a problem with your innermost while loop. neighbors is a list
(or something similar) while ctr is an int. You can't compare the two. Also,
ctr is not the variable iteration through neighbors. It's a counter. Do
something like this.

    
    
    i = 0
    ctr = 0
    while i < len(box): 
        if eval(Box(boxWidth,boxHeight,box_edges,box_point)):
           if box_edge in gridList:
                ctr += 1
        i+=1
    

