Recursion problem | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Recursion problem

From sololearn challenge. I just realized that it ia a recursion problem. Please check out these two "slighly" different code. Could you explain to me? https://code.sololearn.com/ca8r7ptqbD0L/?ref=app https://code.sololearn.com/cBybHbk8N9Ys/?ref=app

24th Dec 2022, 3:02 AM
Oliver Pasaribu
Oliver Pasaribu - avatar
1 Antwort
+ 2
In "recursion problem.cpp", argument <i> is decremented and printed ONLY inside an `if` conditional block. In "recursionw.cpp" argument <i> is printed freely. The printing statement is not restricted by the `if` conditional because the `if` conditional omitted the curly brackets block marker {}, which means only the next line following the `if` construct is guarded by the conditional. This is common behaviour with loops & conditionals. Without curly brackets surrounding its body, only the first one line following the loop / conditional is considered as part of its body.
24th Dec 2022, 3:15 AM
Ipang