码迷,mamicode.com
首页 > 其他好文 > 详细

循环递归的区别?

时间:2017-02-09 21:50:29      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:print   ati   strong   static   int   system   递归   区别   重复执行   

循环:

重复执行一段代码,递归,遍历,迭代都属于循环。

代码举例:

1  for(int x = 10; x < 20; x = x+1) {
2          System.out.print("value of x : " + x );
3          System.out.print("\n");
4       }

递归:

重复调用自身的,如下例子不断调用自身方法。

代码举例:

1    private static int fab(int index) {  
2         if (index == 1 || index == 2) {  
3             return 1;  
4         } else {  
5             return fab(index - 1) + fab(index - 2);  
6         }  
7     }

 

循环递归的区别?

标签:print   ati   strong   static   int   system   递归   区别   重复执行   

原文地址:http://www.cnblogs.com/androidsuperman/p/6384027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!