Re: [pygame] Break outside the loop

2007-11-26 Thread Luke Paireepinart

Ian Mallett wrote:
On Nov 22, 2007 9:01 PM, Luke Paireepinart [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


On Nov 21, 2007 12:27 PM, Ian Mallett  [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] wrote:

For one thing, I think that he meant for this:
[snip]

I know what he meant.  I didn't understand the error that his
incorrect code _did_ generate, and I was asking if anyone else did
understand.

I wasn't talking specifically to you, more to J.K.  I was noting a 
problem which I think will cause the program to fail.
Well, it was confusing because you said he as if speaking to me about 
someone else (so would that make JK an indirect object?)




Re: [pygame] Break outside the loop

2007-11-26 Thread Ian Mallett
On 11/26/07, Luke Paireepinart [EMAIL PROTECTED] wrote:
 Well, it was confusing because you said he as if speaking to me about
 someone else (so would that make JK an indirect object?)
No matter.

With for loops, one can use break to immediately exit, continue
to break the current iteration and continue with the next.  I'm not
sure if that's all, though.

Incidentally, I'm curious if any of this has helped to fix the
problem?  I get the feeling that recently, someone asks a question and
gets a barrage of quasi-related discussion in return.

Ian


Re: [pygame] Break outside the loop

2007-11-23 Thread Ian Mallett
On Nov 22, 2007 9:01 PM, Luke Paireepinart [EMAIL PROTECTED] wrote:

 On Nov 21, 2007 12:27 PM, Ian Mallett  [EMAIL PROTECTED] wrote:

  For one thing, I think that he meant for this:
  [snip]
 
 I know what he meant.  I didn't understand the error that his incorrect
 code _did_ generate, and I was asking if anyone else did understand.

I wasn't talking specifically to you, more to J.K.  I was noting a problem
which I think will cause the program to fail.


Re: [pygame] Break outside the loop

2007-11-22 Thread Luke Paireepinart
On Nov 21, 2007 12:27 PM, Ian Mallett [EMAIL PROTECTED] wrote:

 For one thing, I think that he meant for this:
 [snip]

I know what he meant.  I didn't understand the error that his incorrect code
_did_ generate, and I was asking if anyone else did understand.


Re: [pygame] Break outside the loop

2007-11-22 Thread Sami Hangaslammi
On Nov 23, 2007 7:01 AM, Luke Paireepinart [EMAIL PROTECTED] wrote:
 I know what he meant.  I didn't understand the error that his incorrect code
 _did_ generate, and I was asking if anyone else did understand.

It's a bit unclear what the supposed indentation in the original code
is. If you paste it to an editor as-is, Python complains that
unindent does not match any outer indentation level (since the while
is indented incorrectly). Unless the original poster provides the code
as an attachment or using e.g. some paste-bin web service (that
correctly retains indentation), it's impossible to say for sure what
caused the break outside of loop error. You're right that it looks
like the break should affect the for y in range -loop.

-- 
Sami Hangaslammi


Re: [pygame] Break outside the loop

2007-11-21 Thread Sami Hangaslammi
On Nov 21, 2007 8:27 PM, Ian Mallett [EMAIL PROTECTED] wrote:
 while 1:
 grid.update()
 try:
 explorer.next()
 except StopIteration:
 break

 By the way, except StopIteration can be replaced by just: except,
 because there are no futher conditional excepts.

Absolutely not. That would silently mask all errors that could happen
inside next leading to potentially hard to debug bugs. Empty
catch-all except-blocks should only be used in very rare cases where
you want to process all errors in the same way (e.g. some logging code
that the program root level).

-- 
Sami Hangaslammi


Re: [pygame] Break outside the loop

2007-11-21 Thread Luke Paireepinart

Joseph king wrote:

I keep getting a ***'break' outside the loop error on this code can anyone help


 for y in range(8):
 for x in range(8):
   c = Canvas()
   c.grid(column=x, row=y)
# make a grid
   grid = Grid(c, cellsize_x=8, cellsize_y=8, gridsize_x=10, gridsize_y=10)
# get the maze generator
   explorer = MazeBuilder(grid)

while 1:
  grid.update()
try:
  explorer.next()

except StopIteration:
break
  

I'm not really too clear on what's happening here.
You can use break to get out of for loops, can't you?
Shouldn't this just be a logical error, and just get hung in the while 
loop (since it has no exit condition)?
Or is the problem that the 'while 1' is tabbed over slightly less than 
the inner 'for x in range(8)' which is somehow causing

it to be outside of the outer for loop, or something?
I'd appreciate it if someone could explain that.
-Luke


Re: [pygame] Break outside the loop

2007-11-21 Thread Ian Mallett
For one thing, I think that he meant for this:

while 1:
grid.update()
try:
explorer.next()
except StopIteration:
break

...to be this:

while 1:
grid.update()
try:
explorer.next()
except StopIteration:
break

By the way, except StopIteration can be replaced by just: except,
because there are no futher conditional excepts.

Ian


Re: [pygame] Break outside the loop

2007-11-15 Thread Jason Ward
your break is outside of the loop.
if you run this:

break

you will get the same error because that's exactly what your doing,
there is no loop to break out of.


Re: [pygame] Break outside the loop

2007-11-14 Thread Ian Mallett
In this case, it looks like your except thing happens after the loop ends.
(StopIteration).  Replace it with 'pass', and it should work.
Ian


Re: [pygame] Break outside the loop

2007-11-14 Thread David Muffley
On Nov 14, 2007 9:52 PM, Joseph king [EMAIL PROTECTED] wrote:

 I keep getting a ***'break' outside the loop error on this code can anyone
 help


  for y in range(8):
 for x in range(8):
   c = Canvas()
   c.grid(column=x, row=y)
# make a grid
   grid = Grid(c, cellsize_x=8, cellsize_y=8, gridsize_x=10,
 gridsize_y=10)
# get the maze generator
   explorer = MazeBuilder(grid)

while 1:
  grid.update()
try:
  explorer.next()

except StopIteration:
break
 c.mainloop()


From what I can gather, it looks as if you wanted
while 1:
grid.update()
try:
explorer.next()
except StopIteration:
break

with try/except in the while loop?  As you have it, the break is outside of
the loop.