exchange
This function exchanges the contents betweeen two variables, one variable and one entry in the table, or between two table entries. Note: Regarding variables, only the value in the base variable will be exchanged. Member variables will not be touched
Indirect parameter passing is disabled
2
No. | Type | Description |
---|---|---|
1 io |
all types | Variable or table entry 1 |
2 io |
all types | Variable or table entry 2 |
a[] = Abel; a[Age] = 30;
b[] = Beata; b[Age] = 31;
exchange( a[], b[] );
echo( "Using exchange(...): Only base variables are exchanged.");
echo( " a[]: ", a[], ", ", a[Age] );
echo( " b[]: ", b[], ", ", b[Age] );
table initialize( t, { { Name, Age}, {Corinne, 32} } );
exchange( a[], [t:Name,1] );
exchange( a[Age], [t:Age,1] );
echo( new line, "Exchanged with table entry: ");
echo( "table: ", [t:Name,1] );
echo( " a[]: ", a[], ", ", a[Age] );
// In case you want to exchange base variables with their members, use transactions.
a[] = Abel; a[Age] = 30;
b[] = Beata; b[Age] = 31;
a[] <=> b[];
echo( new line, "Using transactions: Members are also exchanged");
echo( " a[]: ", a[], ", ", a[Age] );
echo( " b[]: ", b[], ", ", b[Age] );
Using exchange(...): Only base variables are exchanged.
a[]: Beata, 30
b[]: Abel, 31
Exchanged with table entry:
table: Beata
a[]: Corinne, 32
Using transactions: Members are also exchanged
a[]: Beata, 31
b[]: Abel, 30
Transactions
<=>