is there something I’m completely missing about us...
# getting-started
d
is there something I’m completely missing about using a while loop within a for loop? The while loop is looping over a list of JSwing nodes, the for loop is iterating over a list of items but the for loops only runs a single time then just does not loop, I don’t get it. I originally tried a foreach, and now I’m just adding print statements to try to understand what I’m doing wrong. I know this code is not the cleanest/most correct lol. Learning Kotlin as I go
and to clarify the
size
prints as 29 and the
idx
var never increments above 0
m
hard to debug someone else's code, but idx should increment. So what happens? You just go past the try? Do you catch an error?
also, debugging by printing is generally not smart if you just have access to the debugger
d
thanks @Michael de Kaste! I ended up running it through the debugger and still not sure of what was causing issue in first place but reworked some code and it loops as expected 🤷‍♂️
n
aside: I'd convert that Enumeration into anything else first...using
Collections.list()
maybe. or maybe there's a asSequence adapter you can use/write
d
appreciate it, I’ll look to do that. Is there specific performance or readability reasons for the change?
n
Enumerations are just very...Java 1.0. doesn't look like you can even use them directly in for-each, right? manually iterating things can be a source of errors
if it was a sequence or list you wouldn't need that
parent.userObject is FlagNodeParent
check either; you could use
.filterIsInstance<FlagNodeParent>
d
lol I’m not entirely sure myself, I found a project to use Kotlin on to also learn some about the JVM. Loving Kotlin so far, but I’m very much in the early stages of my understanding
n
if you pasted another version with all the debug statements and commenting code removed, and enabled Kotlin syntax highlighting...that would make it easier for others to read.
you've tried attaching a debugger, too? often that's the best way to see what's going on
oh sorry, yeah you tried that
eh, I guess it's working now?
d
for this problem 😄 onto other ones of my own making with lack of understanding. Thanks again for the help and pointers!
n
image.png