Thread: another arduino question

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    808

    another arduino question

    im watching these videos produced by a supposed high school instructor he is introducing while loops

    he had a code that flashed a red led 5 times and then a yellow led 5 times using two for loops so he said lets modify this code to use while loops and does one as an example.

    Code:
    void loop
    {
        int j = 1
    
        while ( j <= numblinks )// numblinks is a global variable
        {
        //do stuff
        }
    
        for (int j =1: j <= numblinks; j = j+1)
        {
        //do stuff
        }
    }
    this code is then compiled and uploaded to the arduino and runs

    2 questions arise
    1)can you not use j++ or even j += 1 on the arduino
    2)even more importantly does the arduino not care that j is declared twice
    coop

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by cooper1200
    1)can you not use j++ or even j += 1 on the arduino
    I know the answer to this despite having never programmed for the Arduino because I was able to search the Web. Alternatively, you can try it yourself when you actually have an Arduino.

    Quote Originally Posted by cooper1200
    2)even more importantly does the arduino not care that j is declared twice
    The second declaration of j likely hides the first. Write a program to find out.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. programing the arduino
    By cooper1200 in forum C Programming
    Replies: 2
    Last Post: 06-17-2019, 03:51 PM
  2. C and Arduino
    By bamwels in forum C Programming
    Replies: 11
    Last Post: 08-21-2013, 09:20 PM
  3. arduino
    By Annonymous in forum Tech Board
    Replies: 7
    Last Post: 05-29-2012, 11:13 PM
  4. Arduino project programming question
    By qtip2293 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2011, 03:57 PM
  5. Arduino programming
    By Terese in forum C++ Programming
    Replies: 5
    Last Post: 12-11-2010, 01:03 PM

Tags for this Thread