| ���� Python �̳� | ��6�� ������ | |
|---|---|---|
| ��һҳ | break��� | ��һҳ |
break��������� ��ֹ ѭ�����ģ�������ѭ������û�г�ΪFalse�����л�û�б���ȫ�ݹ飬Ҳִֹͣ��ѭ����䡣
һ����Ҫ��ע���ǣ�������for��whileѭ���� ��ֹ ���κζ�Ӧ��ѭ��else�齫��ִ�С�
#!/usr/bin/python
# Filename: break.py
while True:
s = raw_input('Enter something : ')
if s == 'quit':
break
print 'Length of the string is', len(s)
print 'Done'
��Դ�ļ���code/break.py��
$ python break.py
Enter something : Programming is fun
Length of the string is 18
Enter something : When the work is done
Length of the string is 21
Enter something : if you wanna make your work also fun:
Length of the string is 37
Enter something : use Python!
Length of the string is 12
Enter something : quit
Done
����������У����Ƿ�����ȡ���û������룬Ȼ���ӡÿ������س��ȡ������ṩ��һ���ر��������ֹͣ���������û��������Ƿ���'quit'��ͨ�� ��ֹ ѭ����������β��ֹͣ����
�����ַ����ij���ͨ���ڽ���len����ȡ�á�
��ס��break���Ҳ������forѭ����ʹ�á�
�������������������д��һ��Сʫ����ΪG2��Pythonʫ��
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
| ��һҳ | ��һ�� | ��һҳ |
|---|---|---|
| forѭ�� | ��ҳ | continue��� |