// relates to this Aarduino-Forum-thread https://forum.arduino.cc/t/how-to-decrement-a-variable-in-every-line-of-a-loop/1265739/32
// this is the WOKWI-Link: https://wokwi.com/projects/399298310078465025
// "byte" is the datatype of the array
// "myPhoneDigits" is the name of the array
// the "4" defines how many elements the array shall have
byte myPhoneDigits[4]; // declaring an array of byte with 4 elements named "myPhoneDigits"
void setup() {
// make sure to adjust baudrate of the
//Arduino-IDE serial monitor to 115200 baud
Serial.begin(115200);
Serial.println( F("Setup-Start") );
// store values in each array-element
myPhoneDigits[0] = 4; // element 1 which has index nr 0
myPhoneDigits[1] = 9; // element 2 which has index nr 1
myPhoneDigits[2] = 5; // element 3 which has index nr 2
myPhoneDigits[3] = 1; // element 4 which has index nr 3
Serial.println();
Serial.println();
Serial.println("all phone-digits printed as fixed characters");
Serial.println("Index-Nr 0123");
Serial.println("the digits 4951");
Serial.println();
Serial.println("now printed in a for-loop");
Serial.print("the digits ");
for (int i = 0; i < 4; i++) { // count up 0 to 3
Serial.print(myPhoneDigits[i]); // print content of each array-element
}
Serial.println();
Serial.println();
Serial.println("now printing with explanation");
Serial.println("each array-element and its content");
for (int i = 0; i < 4; i++) { // count up 0 to 3
Serial.print("array-element myPhoneDigits[");
Serial.print(i); // print index-number
Serial.print("] holds value ");
Serial.println(myPhoneDigits[i]); // print content of each array-element
}
Serial.println("Scroll back serial monitor to read all printed lines");
}
void loop() {
}