Loops with else

Hi,
i want to write following conditions with FF++: we suppose that a1<a2.
is it true to write:
for (real t=0, t<T, t+=dt)
{
if (t < a1) {…}
else if (t>a1)&(t<a2) {…instructions…}
else if (t > a1) & (t>a2) {…instructions…}
}
?

Regards

I think you should use the logical and: && so

if (t < a1) {…}
else if ((t>a1)&&(t<a2)) {…instructions…}
else if ((t > a1) && (t>a2)) {…instructions…}

alternatively you can write

if (t < a1) { instruction here t<a1}
else{ here t>=a1
if (t<a2) {…instructions…here t>=a1 and t<a2}
else {…instructions…here t>=a1 and t>=a2}
}

I hope this helps

1 Like