# python循环中的else_python 循环中else的简单示例

# @param 你所不知道的python 循环中的else

# @author 编程之家 jb51.cc|www.www.jb51.cc

numbers = [1,2,3,4,5]

for n in numbers:

if (n > 5):

print('the value is %d '%(n))

break

else:

print('the for loop does not end with break')

i = 0

while(numbers[i] < 5):

print('the index %d value is %d'%(i,numbers[i]))

if (numbers[i] < 0) :

break

i = i + 1

else:

print('the loop does not end with break')

numbers = [1,5]

for n in numbers:

if (n > 5):

print('the value is %d '%(n))

break

else:

print('the for loop does not end with break')

i = 0

while(numbers[i] < 5):

print('the index %d value is %d'%(i,numbers[i]))

if (numbers[i] < 0) :

break

i = i + 1

else:

print('the loop does not end with break')

# End www.jb51.cc

# @param 你所不知道的python 循环中的else

# @author 编程之家 jb51.cc|www.www.jb51.cc

C:\Python27>python.exe for_else.py

the for loop does not end with break

the index 0 value is 1

the index 1 value is 2

the index 2 value is 3

the index 3 value is 4

the loop does not end with break

# End www.jb51.cc

07-16 255
01-23 1677
11-23 1万+
06-05 5909
01-31 3万+
02-13 2万+
04-30 2681