# Arduino Forum

## Products => The Arduino Starter Kit and Basic Kit => Topic started by: SheCurvesMobius on May 08, 2015, 07:35 pm

Title: Why does the order of this code change if an LED blinks or not?
Post by: SheCurvesMobius on May 08, 2015, 07:35 pm
Why is it that when I write my code this way in the "FOR LOOP A", pin 10 blinks during "FOR LOOP A":

Code: [Select]
`int timer = 100;void setup() {  // Initialize each pin as an output  for (int thisPin = 2; thisPin < 8; thisPin++) {    pinMode(thisPin, OUTPUT);  }  pinMode(10, OUTPUT);}void loop() {  // "FOR LOOP A"  // loop from the lowest pin to the highest:  for (int thisPin = 2; thisPin < 8; thisPin++) {    digitalWrite(thisPin, HIGH);    delay(timer);    digitalWrite(thisPin, LOW);    digitalWrite(10, HIGH);    delay(timer);    digitalWrite(10, LOW);   }   // "FOR LOOP B"  // loop from the highest pin to the lowest:  for (int thisPin = 7; thisPin >= 2; thisPin--) {    digitalWrite(thisPin, HIGH);    delay(timer);    digitalWrite(thisPin, LOW);      }}`

But if I write it this way in the "FOR LOOP A", it stays on for all of "FOR LOOP A" and then turns off right before "FOR LOOP B" starts? I can't understand the logic. I feel like it should blink durring "FOR LOOP A".

Code: [Select]
`int timer = 100;void setup() {  // Initialize each pin as an output  for (int thisPin = 2; thisPin < 8; thisPin++) {    pinMode(thisPin, OUTPUT);  }  pinMode(10, OUTPUT);}void loop() {  // "FOR LOOP A"  // loop from the lowest pin to the highest:  for (int thisPin = 2; thisPin < 8; thisPin++) {    digitalWrite(thisPin, HIGH);    digitalWrite(10, HIGH);    delay(timer);    digitalWrite(thisPin, LOW);    digitalWrite(10, LOW);   }   // "FOR LOOP B"  // loop from the highest pin to the lowest:  for (int thisPin = 7; thisPin >= 2; thisPin--) {    digitalWrite(thisPin, HIGH);    delay(timer);    digitalWrite(thisPin, LOW);      }}`

`int timer = 100;void setup() {  // Initialize each pin as an output  for (int thisPin = 2; thisPin < 8; thisPin++) {    pinMode(thisPin, OUTPUT);  }  pinMode(10, OUTPUT);}void loop() {  // "FOR LOOP A"  // loop from the lowest pin to the highest:  for (int thisPin = 2; thisPin < 8; thisPin++) {    digitalWrite(thisPin, HIGH);    digitalWrite(10, HIGH);    delay(timer);    digitalWrite(thisPin, LOW);    digitalWrite(10, LOW);    delay(timer);  }  // "FOR LOOP B"  // loop from the highest pin to the lowest:  for (int thisPin = 7; thisPin >= 2; thisPin--) {    digitalWrite(thisPin, HIGH);    delay(timer);    digitalWrite(thisPin, LOW);    delay(timer);  }}`
{"ft_lang_label":"__label__en","ft_lang_prob":0.67815924,"math_prob":0.9406721,"size":2469,"snap":"2020-34-2020-40","text_gpt3_token_len":703,"char_repetition_ratio":0.21663286,"word_repetition_ratio":0.6354916,"special_character_ratio":0.3203726,"punctuation_ratio":0.20366599,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9669544,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-20T16:37:57Z\",\"WARC-Record-ID\":\"<urn:uuid:3df2028b-689b-49e8-b1b7-52188cca3d52>\",\"Content-Length\":\"8646\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f6ef2939-c846-4e29-9a69-ea815a45e7f6>\",\"WARC-Concurrent-To\":\"<urn:uuid:808ca8d5-6815-4678-9dff-91bf264fa029>\",\"WARC-IP-Address\":\"104.22.48.75\",\"WARC-Target-URI\":\"https://forum.arduino.cc/index.php?action=printpage;topic=321641.0\",\"WARC-Payload-Digest\":\"sha1:GM7VANLFZHTNS4MRG7UZRPNNDK2K5DEE\",\"WARC-Block-Digest\":\"sha1:MXHNQ5Y4XOYM7CGSGKQGRWYCOA4POKIK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600400198287.23_warc_CC-MAIN-20200920161009-20200920191009-00264.warc.gz\"}"}