----- 什么是多重循环 ---- 打印数列 public class ForEx { public static void main(String[] args){ for(int i = 100; i >= 5; i=i-5){ System.out.print(i+" "); } /* int i = 100; while(i>=5){ // System.out.print(i+" "); i-=5; }*/ // int i = 100
Python 本身没有“break n” 和“goto” 的语法,这也造成了Python 难以跳出多层(特定层数)循环.下面是几个跳出多层(特定层数)循环的tip. 1.自定义异常 class getoutofloop(Exception): pass try: for i in range(5): for j in range(5): for k in range(5): if i == j == k == 3: raise getoutofloop() else: print i, '-
方法1:自定义异常 # -*- coding:utf-8 -*- """ 功能:python跳出循环 """ # 方法1:自定义异常 class Getoutofloop(Exception): pass try: for i in range(5): for j in range(5): if i == j == 2: raise Getoutofloop() else: print i, '----', j except Getoutoflo