can I use a for statement to code variables?

I have a lot of variables to use in a timer sketch and I am tying to save space! Can I do something like this?

for (int X=0; X < 16; X++){
int varTimer"X";
}

and it give me varTimer1, varTimer2, varTimer3, ect.... to varTimer16

I do know that this code will not work! But is there a way to make it work?

Thanks for the help

No, but post your code.

You cannot do what you describe but I can see arrays in your near future.....

use an array.

I am tying to save space!

Save space where? How? If you mean "save typing", arrays are your friends.

This is as much as I have now!

#include <Time.h>
#include <TimeAlarms.h>

for (int X=0; X < 16; X++){
int varTimer"X";
}

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

In your Arduino IDE: File->Examples->05 Control->Arrays

And if you want to save space, change every occurrence of int to short or byte, either should work. The examples all have room for improvement, it's the idea that counts.

so maybe

int varTimer[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

I'll try it thanks

Neither the type (int) nor the values seem particularly sensible for a variable whose name suggests it holds times, but that is the correct syntax to declare an array and give it initial values.

Thanks for your help this works and was easy I should have been able to get it by myself!

#include <Time.h>
#include <TimeAlarms.h>

byte varTimer[16] = {};

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:
varTimer[2] = 1; // This does assign position 3 to the value of one
}

Thanks again

You're on the way, keep rolling.

Check out more of the examples from time to time. I have found that modifying code that works is a great way to start out most programs, and I've been coding for a while now.

  varTimer[2] = 1;           // This does assign position 3 to the value of one

No. It assigns the value 1 to the 3rd position in the array.