Array generated by loops

I have an issue making an array by for. The idea is to generate the diagonal of the array by a progression, and then replicate that value for the lower part of the array. The part that makes the diagonal works just fine, but the part that replicate the diagonal value for the lower part of the array messed up at column n-2 (it's always the n-2 column that fails). At this point I'm at lost of what is failing.

Here is the code:

Clear["Global*"]
n=6;
V=Array[v,n+1,0];
v[0]=0;

A=Array[a, {n, n}];
For[i=1,i<=n,i++,
a[i,i]=V[[i+1]];
For[j=1, j<=i,j++,
a[i,i]=Append[{a[i, i]}, j*p+V[[1+i-j]]];
];
if[i<n, A[[i + 1 ;; n, i]] = a[i, i]];
]
MatrixForm[A]


Any feedback is welcome, ty

• if is not a Mathematica command; use If. Moreover it is unclear to me what you want. Probably you mix up a[i,j] and A[[i,j]]. Only the latter indexes into an array. – Henrik Schumacher Mar 24 '18 at 21:08
• To add onto what @HenrikSchumacher said unless it's inside Compile using For is probably not the best way to approach your problem – b3m2a1 Mar 24 '18 at 21:23
• Yeah, Do is in many ways more robust, faster, and more concise than For. – Henrik Schumacher Mar 24 '18 at 21:40
• Thanks for the feedback. I changed the If, but the strange behavior persist. there is no issue with the a[i,j] and A[[i,j]]` , if that were the case it would fail at every iteration not just at the n-2. – Rodrigo Mar 25 '18 at 0:16