Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is a js recursive function call

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is js recursive function call". In daily operation, I believe that many people have doubts about what is js recursive function call. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "what is js recursive function call"! Next, please follow the editor to study!

A recursive call is a special nested call, which is called again by a function or after calling other functions. As long as the function calls each other to produce a loop, it must be a recursive call, recursively calling a solution. One is logical thinking, which divides a big work into smaller and smaller tasks. For example, a monk has to move 50 stones. He thinks, as long as 49 stones are removed first. Then the remaining piece can be moved, and then consider the 49 yuan, as long as the first move 48, then the remaining piece can be moved, recursion is a kind of idea, but in the program, it is realized by the feature of function nesting.

Basic information of recursive call

Define

A recursive call is to call the current function in the current function and pass it to the corresponding parameters. this is an action, which is carried out layer by layer, and does not stop the recursive call until the general situation is satisfied. start returning from the last recursive call.

English

Recursiveinvocation

Function model

Fun (formal parameter) {

Fun (parameter value 1) / / first recursive call

Fun (parameter value 2) / / second recursive call

An example of recursive call

Recursion in C language

Code for calculating factorials

Longfact (longn)

{

If (naughty 0 | | naughty 1) return1L

Elsereturnn*fact (nmur1)

}

This function is called fact, and it calls itself, which is a typical recursive call, and the call process is similar to a stack.

Note: the main tone function is also the modulated function. Executing a recursive function calls itself repeatedly. Every time it is transferred, it enters a new level.

Intf (intx)

{

Inty

Zasthf (y)

Returnz

This function is a recursive function. But running this function will call itself endlessly, which is certainly not true. In order to prevent the recursive call from happening indefinitely, there must be a means to terminate the recursive call within the function. The common method is to add conditional judgment, after meeting certain conditions, no longer make recursive calls, and then return layer by layer. The following example illustrates the execution of a recursive call.

Note: linked lists are recursive calls to some extent.

Recursion in Pascal

Const

Zhuang 10000

Var

A: Array [0.. z + 1] ofinteger

N,j,i,k:longint

At this point, the study on "what is a js recursive function call" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 253

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report