Why if/else and not for in sliderValueChanged method?


Hi everyone

I’m working on a project where I have created an array of sliders in a child component. In my parent component I’ve set up listeners on all sliders but I’m experiencing something weird that’s probably due to my newbyness so forgive me if the solution is idiotically obvious.

When I move a slider, the void MainContentComponent::sliderValueChanged
method method gets called. But it only works if I use an if/else statement inside of it and not – which would be more convenient for me – if I use a for-loop. Here’s the full method that:

void MainContentComponent::sliderValueChanged (Slider *slider){

std::cout << “Slider done changed!!!”;

// This works
if (slider == horizontalMixer1.sliders[0]) {
    std::cout << "Which one? No:" << String(0) << "\n";

// But this doesn't ?
for (int i; i < horizontalMixer1.numberOfSliders; i++){
    if (slider == horizontalMixer1.sliders[i]) {
        std::cout << "Which one? No:" << String(i) << "\n";



LOL. Because I didn’t initalize i to anything in my for-loop. Sorry, move on… nothing to see here.