A recursive function does not work as I expect it New comment DVS75 2019.09.21 20:40 This recursive function should return "1" in the first call (with "3"), but it still returns "false" ("0"). int init() { Print ("3: ",recursiveFunction(3)); Print("12: ",recursiveFunction(12)); Print("25: ",recursiveFunction(25)); } bool recursiveFunction (int a=0, int counter=1) { if (a+3==15) { Print ("Attempt # ",counter," was successful."); return (true); } else if (a<12) { counter++; recursiveFunction (a+1,counter); } else return (false); } Output: 25: 0 12: 1 Attempt # 1 was successful. 3: 0 Attempt # 9 was successful. Please let me know why this happens. With any value of "a" that is less than 12 the function should still return "true" eventually, I think. Thank you. Errors, bugs, questions iRSIOnArray Issues Questions on the SI language William Roeder 2019.09.21 21:29 #1 When you recurse, you do not return anything. New comment
This recursive function should return "1" in the first call (with "3"), but it still returns "false" ("0").
Output:
Please let me know why this happens.
With any value of "a" that is less than 12 the function should still return "true" eventually, I think.
Thank you.