Assignments

The assignment statement assigns a value (Expr1) to a variable (Ref) of a transaction. If the variable is an array, you must reference the element of the array via an index. You can only assign elements of an array, not the whole array. If the variable is a string, you can assign single characters to the string by referencing the string variable via an index.

Syntax

Stat = Ref ":=" Expr1 . 
Ref  = ident [ "[" Expr2 "]" ] .

For numerical variables additional assignment operators are allowed:

Stat = Ref [ "+=" | "-=" | "*=" | "/=" ] Expr1 .
Ref = ident [ "[" Expr2 "]" ] .

Example

The following assignments are valid:

dclrand 
  r1 : RndUniN(0..255);  
  r2 : RndStr(2..10); 
  ... 

dcltrans 
  transaction t1(p1: number): 
  var   
    i, j, k : number init 1; 
    a       : array[10] of number; 
    b1, b2  : boolean; 
    s1      : string(20); 
    s2      : string(10); 
    as      : array [5] of string(14);
    f       : float init 1.0;

  begin 
    a[1] :=1; 
    i := i*j+1; 
    k := i modj+1; 
    i := j/(i+k); 
    i := ((k+i*(i+1))/(k+k*a[2]))/199; 
    j := -j;
    i := ord(chr (r1)); 
    j := ord(s1[a[i]]); 
    k := ord('a')+10; 
    a[i] := p1; 
    b2 := true; 
    b1 := i>j; 
    b2 := i<>p1; 
    b1 := j>=r1; 
    b2 := i*j=p1;
    b2 := b1=(i<j); 
    b1 := (i<=j) and b1 or not (b2 or b1); 
    s1 := s2;
    s2 := r2;
    s1[i] := s2[j+1]; 
    s2[10] :='x'; 
    as[2] := s2; 
    as[3] :="Silk Performer"; 
    as[4] := r2;
    s1[1] :=chr(r1);
    s1[1] :=chr(ord('a'))

    j += 2; // is the same as j := j + 2;
    j -= 2; // is the same as j := j - 2;
    j *= 2; // is the same as j := j * 2;
    j /= 2; // is the same as j := j / 2;

    f += 2.0; // is the same as f := f + 2.0;
    f -= 2.0; // is the same as f := f - 2.0;
    f *= 2.0; // is the same as f := f * 2.0;
    f /= 2.0; // is the same as f := f / 2.0;

  end t1;