Variable name incrementation

E

everett

How do you increment a variable name in loop. For example I have a
variable K1 and I want to increment the name by one everytime I go
through the loop to K2, K3, K4 and so on. Thanks.
 
A

Andreas

everett said:
How do you increment a variable name in loop. For example I have a
variable K1 and I want to increment the name by one everytime I go
through the loop to K2, K3, K4 and so on. Thanks.

I think the simplest way is useing an array. But if you'll stick to names
generative programming in conjunction with loop unrolling may help you

Andreas
 
J

John Harrison

everett said:
How do you increment a variable name in loop. For example I have a
variable K1 and I want to increment the name by one everytime I go
through the loop to K2, K3, K4 and so on. Thanks.

You cannot increment a variable name, in a loop or anywhere else.

Perhaps you need to use an array instead of a variable. Post the code you
are having difficulty with.

john
 
J

Jon Bell

How do you increment a variable name in loop.

You can't.
For example I have a
variable K1 and I want to increment the name by one everytime I go
through the loop to K2, K3, K4 and so on. Thanks.

Why not use an array, or better, a vector?

vector<double> K(10);

for (int pos = 0; pos < 10; ++pos)
{
// do something with K[pos]
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top