Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
For loop calling recursive function looping infinitely

I'm trying to make a program that would draw bones that are connected to each other at their ends, just by recursively running through that bone's children. The issue is that when a bone has more than two children it attempts to draw the second one an infinite number of times.

var bones={
    torso:{
        attached:["arm","arm2"]
    },
    arm:{
        attached:[]
    },
    arm2:{
        attached:[]
    }
}

drawBone("torso")
function drawBone(bone){
    console.log(bone)
    let attBones = bones[bone].attached;
    for(i = 0; i < attBones.length; i++){
        drawBone(attBones[i])
    }
}

From what I've found, i inside the for loop gets stuck at 1 somehow. I'm not super familiar with recursion, so there might be something fundamentally wrong I'm doing.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!