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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:29:47+00:00 2026-05-22T12:29:47+00:00

My question is about the second break statement: if x == xstart and y

  • 0

My question is about the second break statement:
if x == xstart and y == ystart:
break

So this break statement breaks out of the while true loop correct? But then does it go back to the next closest loop (namely the while board[x][y] = OtherTile:) But because this condition is not met, it goes back to the original for xdirection, ydirection loop? I just wanted to see if my understanding was correct.

if board[xstart][ystart] not OnBoard(xstart, ystart) or board[xstart][ystart] != ' ':
    return False

#temporarily set the tile on the board, but change it back to a blank before the end of this function
board[xstart][ystart] = tile

#Set computer tile
if tile == 'X':
    OtherTile = 'O'
else:
    OtherTile = 'X'

#empty list of tiles to flip
TilesToFlip = []

#this is a for loop for two variables.  Each list of two represents a position away from the orignal spot
for xdirection, ydirection in [[1,0], [0,1], [-1,0], [0,-1], [1,-1], [1,1], [-1,1], [-1,-1]]:

    #we set x and y to the original coordinates passed to us because we want to preserve the orignal values
    x, y = xstart, ystart
    x = x + xdirection
    y = y + ydirection

    #after the first iteration, check to see if the adjacent piece is on the board and if it's the OtherTile:
    if isOnBoard(x,y) and board[x][y] == OtherTile:
        x = x + xdirection
        y = y + ydirection
        #if the next piece is not on the board, go back to the for loop to test another direction
        if not isOnBoard(x,y):
            continue
        while board[x][y] = OtherTile:
            x = x + xdirection
            y = y + ydirection
            #we break here because if we had just continued it would have gone back to the while loop.
            #since we're breaking, it goes back to the original for loop (if it goes off the board)
            if not isOnBoard(x,y):
                break

        #it finishes with the while loop if it reaches a tile that is not the OtherTile (i.e. it's blank or it's the player's)
        #so we check to see if it's the player's
        if board[x][y] == tile:
            #if it is the player's tile, then we go in the reverse direction, appending each tile to the TilesToFlip list
            while True:
                x = x - xdirection
                y = y - ydirection
                #when we reach the original tiles, we break (by then we have all the tiles that need to be flipped in store in the new list)
                if x == xstart and y == ystart:
                    break
                TilesToFlip.append([x,y])
  • 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-22T12:29:48+00:00Added an answer on May 22, 2026 at 12:29 pm

    It will only break the while True loop. The loop will continue forever until x == xstart and y == ystart.

    Once that condition is met, it will continue on in the that outer for loop.

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

Sidebar

Related Questions

No related questions found

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.