Friday 26 July 2019

Processing: Assignment operator


Assignment Operator
Assignment operator is used to assign a value to a variable.
   Syntax
      type variable = value;

   Example
      int a = 10.
      int b = 20

Processing supports compound assignments
   Compound Assignment
      Syntax:
         variable operator= value

      Example:
         let’s say
         int a = 10;
         a+=10 evaluates to a=a+10

Compound Operator
Example
Description
+=
a+=10
a=a+10
-=
a-=10
a=a-10
*=
a*=10
a=a*10
/=
a/=10
a=a/10

Operators.pde
int var1 = 100;
int sum=10, sub=10, mul=10, div=1000;

println("sum+var1 is " + (sum+=var1));
println("sub-var1 is " + (sub-=var1));
println("mul*var1 is " + (mul*=var1));
println("div/var1 is" + (div/=var1));

Output
sum+var1 is 110
sub-var1 is -90
mul*var1 is 1000
div/var1 is10


Previous                                                    Next                                                    Home

No comments:

Post a Comment