FailedFace Posted November 2, 2011 Share Posted November 2, 2011 I've been looking into finding a way to loop through variables via a counter: var v1,v2,v3,v4,v,i:integer; begin v1:=1; v2:=2; v3:=3; v4:=4; repeat writeln(v<i>); i:=i+1; until (i=4) end. So i want to be able to print all of my variables v1 -> v6 via a loop. Is there any way to assign var v to be of type int that takes the place of other vars? (to allow my adding of numbers at the end of the variable to call another variable) Thank for any help i get even if it is a no. Not that it will stop me from trying. Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted November 2, 2011 Share Posted November 2, 2011 (edited) Wouldn't an array better suit your purpose? program New; var v: TIntegerArray; i: Integer; begin SetLength(v, 4); v[0] := 1; v[1] := 2; v[2] := 3; v[3] := 4; for i := 0 to High(v) do writeln(IntToStr(v[i])); end. Or alternately, if you were intent on keeping the number of the vars as 1 through 4: program New; var v: array [1..4] of Integer; i: Integer; begin v[1] := 1; v[2] := 2; v[3] := 3; v[4] := 4; for i := Low(v) to High(v) do writeln(IntToStr(v[i])); end. Edited November 2, 2011 by Bixby Sayz Quote Link to comment Share on other sites More sharing options...
Wanted Posted November 2, 2011 Share Posted November 2, 2011 Don't forgot this var TIA: TIntegerArray; begin TIA := [1, 2, 3, 4, 5]; end. Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted November 2, 2011 Share Posted November 2, 2011 Don't forgot this var TIA: TIntegerArray; begin TIA := [1, 2, 3, 4, 5]; end. Yeah, Don't know why I didn't do that for the initialization. Quote Link to comment Share on other sites More sharing options...
FailedFace Posted November 2, 2011 Author Share Posted November 2, 2011 Yeah an array will do just fine. I assume there are vectors too. Was trying a PHP approach that uses the counter of a for loop to set variables to different values for each iteration by adding an extension on the variable name. I didn't even bother to check that arrays were supported, not that it would have been special for arrays to exist with SCAR, just had a momentary laps in judgement for what data structures I should have been using. Not sure why I did that. Thanks Bixby and Wanted, that was a quick and useful response. Quote Link to comment Share on other sites More sharing options...