Python Forum

Full Version: invalid syntax near break
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I write code

test='C:\Users\Admin\Desktop\test.lst' # folder where must be my test.lst

test='C:/Users/Admin/Desktop/test.lst'
DataSet='C:/Users/Admin/Downloads/mypic/'

data_iter = mx.image.ImageIter(
batch_size=4,
data_shape=(3,816, 1232),
label_width=4,
path_imglist='C:/Users/Admin/Desktop/test.lst',
path_root='DataSet')

for data in data_iter: d = data.data[0]
break
then i get
# error
Error:
for data in data_iter: d = data.data[0] ... break File "", line 2 break ^ SyntaxError: invalid syntax
what's wrong
what's the intended purpose of the break there - it doesn't make sense to have break there (nor it is correct syntax as the error states). break is intended to be in the body of a loop, in order to break out of it before it 'normal' end.

something like this would work:

for data in data_iter:
    d = data.data[0]
    if some_condition_is_True:
        break
Yes, it works, thank you