Need help with simple loop [Beginner Question]

Hey,

so my coding skils are not very good.
I made this little rule for color fade a LED-Strip. It works in general, but it cant exit the loop. It fades the color till restart of OH. You got a solution for this?
Also, is there a better solution for this whole HSB thing?

Wohnzimmer_LED_fade_switch is just a virtual item

rule "Wohnzimmer_LED_fade"
when
	Item Wohnzimmer_LED_fade_switch received update ON
then
var h = 0
var s = 100
var b = 100
var boolean swstate = true


var hsb = h + "," + s + "," + b

do {
	if (Wohnzimmer_LED_fade_switch.state==OFF){
		swstate = false
	}
	hsb = h + "," + s + "," + b
	sendCommand(LED_Stripe_Kueche_Color,hsb)	
 	if (h > 359){
 		h = 0
 	}	
 	h = h + 1
	Thread::sleep(10)
	} while(swstate)
end

Please forgive me my shitty coding skills

Greets
Lucas

please try

} while(Wohnzimmer_LED_fade_switch.state==ON)

I guess changing swstate within the lambda will not change the var outside the lambda.

Still not working. Rule loops till restart of OH

rule "Wohnzimmer_LED_fade"
when
	Item Wohnzimmer_LED_fade_switch received update ON
then
var h = 0
var s = 100
var b = 100

var hsb = h + "," + s + "," + b

do {
	hsb = h + "," + s + "," + b
	sendCommand(LED_Stripe_Kueche_Color,hsb)	
 	if (h > 359){
 		h = 0
 	}	
 	h = h + 1
	Thread::sleep(10)
	} while(Wohnzimmer_LED_fade_switch.state==ON)
end

Not sure if I understand your rule, but to me it looks like Wohnzimmer_LED_fade_switch.state
never changes in your loop; the only changing variable in your loop is h, it ramps up h until h>359, then it resets h to 0, and on and on.
Under what condition would you like to end your loop? when h receives a final value; given that your rule triggers when the item recieved an update on, would this work

do {
	hsb = h + "," + s + "," + b
	sendCommand(LED_Stripe_Kueche_Color,hsb)	
 	h = h + 1
	Thread::sleep(10)
	} while(h<359)

this would exit the loop when h reaches 359…not sure if this is what you want though…

Arrgh… should be

rule "Wohnzimmer_LED_fade"
when
    Item Wohnzimmer_LED_fade_switch received update ON
then
    var h = 0
    var s = 100
    var b = 100
    var hsb = h + "," + s + "," + b
    while(Wohnzimmer_LED_fade_switch.state==ON) {
        hsb = h + "," + s + "," + b
        sendCommand(LED_Stripe_Kueche_Color,hsb)	
         if (h > 359){
             h = 0
        }	
        h = h + 1
        Thread::sleep(10)
    } 
end