Varying duty cycle of a PWM signal

Hi guys,
i want to make a program that alternates the duty cycle of a PWM signal generated by my NUCLEO-F401RE. The duty cycle should be 20% for two periods of the signal and 90% for two periods of the signal. I have chosen a period of 3s. Evaluating the generated signal with another board I see a signal with a costant 20% duty cycle. It never changes. I show you my short code, where are the errors?

#include “mbed.h”

PwmOut pwm1 (D3);
float D=0.9;

int main()
{

pwm1.period(3);

while (1) {

if(D==0.2) D=0.9;
    
else D=0.2;

pwm1.write(D);

ThisThread::sleep_for(6s);

}

}

#include “mbed.h”

PwmOut pwm1 (D3);
float D=0.9;
float C=0.2;

int main()
{
int Duty_Cycle=0;
printf(“Enter the no.of Duty “);//4 times
scanf(”%d”,&Duty_Cycle);
pwm1.period(3XDuty_Cycle);
for(int i=0;i<Duty_Cycle;i++)
{
if(i=<1)
{
pwm1.write(C);//20% Duty Cycle 2 times;
}
elseif(i=<2)
{
pwm1.write(D);//90 Duty Cycle 2 time;
}
}