How to assign multiple values to multiple variables in one line with Pascal

3 Answers

0 votes
program AssignMultipleValuesToMultiple;

var
  a, b, c, d: Integer;
begin
  a := 1; b := 2; c := 3; d := 4;

  WriteLn('Values: ', a:2, ' | ', b:2, ' | ', c:2, ' | ', d:2);
end.


   
(*
run:
  
Values:  1 |  2 |  3 |  4
  
*)

 



answered Jul 14, 2025 by avibootz
edited Jul 14, 2025 by avibootz
0 votes
program AssignMultipleValuesToMultiple;

procedure AssignValues(var w, x, y, z: Integer; val1, val2, val3, val4: Integer);
begin
  w := val1;
  x := val2;
  y := val3;
  z := val4;
end;

var
  a, b, c, d: Integer;
begin
  AssignValues(a, b, c, d, 1, 2, 3, 4);
  
  WriteLn('Values: ', a:2, ' | ', b:2, ' | ', c:2, ' | ', d:2);
end.


   
(*
run:
  
Values:  1 |  2 |  3 |  4
  
*)

 



answered Jul 14, 2025 by avibootz
0 votes
program AssignMultipleValuesToMultiple;

var
  values: array[1..4] of Integer;
  a, b, c, d: Integer;
begin
  values[1] := 6;
  values[2] := 0;
  values[3] := 9;
  values[4] := 5;

  a := values[1]; b := values[2]; c := values[3]; d := values[4];
  
  WriteLn('Values: ', a:2, ' | ', b:2, ' | ', c:2, ' | ', d:2);
end.


   
(*
run:
  
alues:  6 |  0 |  9 |  5
  
*)

 



answered Jul 14, 2025 by avibootz
...