2 action in the same loop

Hallo,

I'm beginner and I try to fit this code I found (https://sites.google.com/site/caddnima/ Version 1.00, 2012-03-13) for my purpose.

how is it possible when the first int reaches 5 to start the next session
as i figure first calculates the first and when finish goes to the next session


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 if (daybyminute >= (ontime*60))
  { 
    if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime/10*9))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
    {
      // fade blue LEDs in from min to max.
      for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0% 
      { 
        analogWrite(blue, bluepercent[i]); 
        lcd.setCursor(2, 1);
        lcd.print(i);
        lcd.print(" "); 
       
        int countdown = ((bluerampup*60)/10); // calculates seconds to next step
        while (countdown>0)
          {
          onesecond(); // updates clock once per second
          countdown--;
         
        }
      }      

      // fade white LEDs in from min to max.
      for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0%
      { 
        analogWrite(white, whitepercent[i]); 
        lcd.setCursor(7, 1);
        lcd.print(i);
        lcd.print(" "); 

        int countdown = ((whiterampup*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          countdown--;
          
        }
      } 
    }
  }


whatever i try its a failure
if you can just explain me what i have to do
thanks in advance
put a break in there

break;
I ' m trying to put an other "while" with no success.

if I understand correct.
Depending on what you are after and if I understand you right.

You can either alter line 6 and change the condition to break on 5 rather than 10. Or you can place an if statement somewhere within the for loop to break when i equals 5.


i want the first to continue counting until the end and when it reaches to 5(at half) to start the next

like this

for (int countdown = [5]) ?

I still have errors

thank you for your answers,
Let's say, that you want to create the loop that outputs numbers from 1 to 10, but when it reaches 5 the next loop starts that, let's say, outputs numbers from 5 to 1. Then previous loop continues.

It should look like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main(){

for(int i = 1; i <= 10; i++){

    if(i == 5){
        for(int j = 5; j > 0; j--){
            cout<<j<<endl;
        }
    }
cout<<i<<endl;
}

return 0;
}

This code is simple enough for you to understand. I think you might want something like that.
If you don't know how to create if statements, check this site:
http://www.cprogramming.com/tutorial/lesson2.html


I think that now you should understand the problem and be able to solve it by yourself. Cheers!:)
either use a break; or continue;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
if (daybyminute >= (ontime*60))
  { 
    if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime/10*9))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
    {
      int main(){
        for (int i = 1; i <= 10; i++)   // setting ib value for 10% increment. Start with 0%
{
       {   
        analogWrite(white, whitepercent[i]); 
        lcd.setCursor(7, 1);
        lcd.print(i);
        lcd.print(" "); 
        )
        if(i == 5){
     for(int j = 5; j > 0; j--){
        int countdown = ((whiterampup*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          countdown--;
          
        }
        } 
        }
        {
      analogWrite(blue, bluepercent[i]); 
        lcd.setCursor(2, 1);
        lcd.print(j);
        lcd.print(" ");
        
        int countdown = ((bluerampup*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          countdown--;
          
        }
        } 
        }
      }
  }
  }



well,
thanks for your time

but it is far above my ability!
Topic archived. No new replies allowed.