Thread: for loop

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    1

    Lightbulb for loop

    Hallo,
    I am trying to write a for loop. But I coul not do it myself. the code is like this

    Code:
    
    uint8_t Read(void){
    
    
    Tem= (int)readTemperature(); /// Reading Temperature from sensor
    
    Hdata= (int)readHumidity(); /// Reading Humidity from sensor
    
    
    numTemp(Tem);    /// sending Temperature data to Display
    
    numHumi(Hdata); /// sending Humidity data to Display
         
    delay (100); ///waiting time 200ms
    }
    
    
    void main(void)
    {
    
    
    
    while(1){
     
              Read();
      	  Read();
     	  Read();
              Read();
     	  Read();
    
    
     	  Read();
     	  Read();
     	  Read();
     	  Read();
     	  Read();
    ///___________________________  1 s
    	         Read();
    	  	  Read();
    	 	  Read();
    	         Read();
    	 	  Read();
    
    
    	 	  Read();
    	 	  Read();
    	 	  Read();
    	 	  Read();
    	 	  Read();
    
    
    	///_________________________________________ 2s
    
    
    
    
          Read();
          Read();
          Read();
          Read();
         Read();
    
    
    	  Read();
    	  Read();
    	  Read();
    	  Read();
    	  Read();
    	///_________________________________________ 3s
    
    
    
    }
    }

    How I can call method "Read()" 30 times ?


    I tried like this:

    Code:
    while(1){
     show = Read();
     for(show = 0; show<= 100; show++);
    But does not work ....

    I appreciate your help .
    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by HammingBird View Post
    I tried like this:

    Code:
    while(1){
     show = Read();
     for(show = 0; show<= 100; show++);
    But does not work ....
    It works, but not the way you want it to.

    You want to do something 30 times, you put it inside a for loop like so:
    Code:
    int i;
    for (i = 0; i < 30; ++i)
    {
        // stuff to repeat goes here
    }
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. While loop in insertNode function is an infinite loop
    By blongnec in forum C Programming
    Replies: 8
    Last Post: 03-19-2016, 09:57 PM
  2. Replies: 1
    Last Post: 03-28-2015, 08:59 PM
  3. Help - Collect data from Switch loop inside While loop
    By James King in forum C Programming
    Replies: 15
    Last Post: 12-02-2012, 10:17 AM
  4. Replies: 1
    Last Post: 12-26-2011, 07:36 PM
  5. Replies: 23
    Last Post: 04-05-2011, 03:40 PM

Tags for this Thread