next up previous contents
Next: Loops Up: Programming Previous: Functions

Branches

if x A end
Depending on the condition x one or several statements A are executed. The condition x must be an arbitrary expression, which evaluates to either 0 or 1. The false-case (i.e. x=0) can lead to another branch B:
if x A else B end
As an example the Heavyside funkcion:
>> function y=H(x)
>    if (x>=0)
>      y=1;
>    else
>      y=0;
>    end
>  end
>> H(-2)
y = 0
>> H(0)
y = 1



Helmut Dersch
2009-03-15