trying to learn how to use ternary operators to refactor some code, but having some issues. This code lights up all the LEDs but they wont go low after they go high. It should light them all up one by one, then turn them all off a few times. Any ideas where I am going wrong?

Hopefully the ternery operator is being used as an academic exercise, because in this context it's pointless. In fact, those two lines can be replaced by simply assigning HighLowToggle to HIGH. You need a persistent variable, like a static or global.

Just guessing... Is the code that turns the LEDs HIGH somewhere else? Here I see that you assign a value HIGH to isHighLow, and immediately test for that value, which results in setting HighLowToggle to LOW. I see no way you can light them on within this function.

Also note, for precision, that HIGH and LOW are defined an integers, not booleans.

[added] This comment was based on code that perhaps I only saw in my dreams, where the values HIGH and LOW were inverted. That didn't work either.

You are setting HighLowToggle to be HIGH in the comparison. But then you never change the variable isHighLow. So every time that comparison gets run isHighLow is still HIGH so the comparison is true and HighLowToggle gets set to HIGH. Make isHighLow a static variable so it doesn't get reinitialized to HIGH every time you call the function and then include a line somewhere that toggles the variable isHighLow and you would be there.

Hopefully the ternery operator is being used as an academic exercise, because in this context it's pointless. In fact, those two lines can be replaced by simply assigning HighLowToggle to HIGH. You need a persistent variable, like a static or global.

yes just trying to learn how to use this by refactoring some messy code. I hear to stay away from Globals, so am trying to avoid learning bad habits.

You are setting HighLowToggle to be HIGH in the comparison. But then you never change the variable isHighLow. So every time that comparison gets run isHighLow is still HIGH so the comparison is true and HighLowToggle gets set to HIGH. Make isHighLow a static variable so it doesn't get reinitialized to HIGH every time you call the function and then include a line somewhere that toggles the variable isHighLow and you would be there.

ok I think I see what you are saying. I will try to work this in. thank you.

[edit] Yet another comment made obsolete by new code. Please disregard.

As an exercise for the ternary operator the syntax is correct, but the logic is flawed.

If you want to do everything in that function, i.e. switch them ON and then OFF, you don't need any 'if' or 'for', just set them to HIGH, add some delay(), turn them LOW one at a time with some delay() within.

If you want to change the previous state, then you cannot initialize the state isHighLow within the function, because that would repeat the same logic every time the function is called. You need to define the state either as a global variable, defined outside any function, or as a static variable, which maintains its value across different function calls. In both cases you don't need a 'for' loop (once they are LOW, the 'for' loop is not going to change their state).

Your first line is wrong, because "HIGH" isn't really a proper keyword for the state of a boolean variable.Even if this compiler lets you do it.

Your second line is wrong for the same reason.

And if you have some boolean variable and you want to use the so-called "ternary operator", there is no needto check the equality of a boolean variable to anything, the boolean variable itself represents the boolean state.