+ 2

How to loop with different values?

I have the code below please help me to create a loop with two values. Any help would be great! https://code.sololearn.com/WcUB4son26zu/?ref=app

10th Apr 2017, 5:38 PM
Waren Gonzaga
Waren Gonzaga - avatar
10 Réponses
+ 10
Is this what you want? for (a;a<=32;a++) { for (b;b<=9;b++) { if (someValue >= a) { document.write("output "+b+" ON"); } else { document.write("output "+b+" OFF"); } } }
10th Apr 2017, 6:11 PM
Tashi N
Tashi N - avatar
+ 9
I think we need some more information... Could you describe what shall happen in your loop? I guess the solution is a nested loop, but I may be wrong...
10th Apr 2017, 5:58 PM
Tashi N
Tashi N - avatar
+ 9
@Waren Sry, it's too late for me and I'm typing on my mobile. I hope someone else can help you. I've bookmarked the question, so if you cannot find a solution, I'll take a look at it again tomorrow. Just post then, I'll see it.
10th Apr 2017, 7:40 PM
Tashi N
Tashi N - avatar
+ 7
for (var i = 0; i < 10; i++){ if(someValue >= i) // output on (use i) else // output off (use i) }
10th Apr 2017, 5:48 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Hello @Tashi N please check the JS code again I revised it... the JS code I want to shorten it into loop thing. Can you loop it?
10th Apr 2017, 6:24 PM
Waren Gonzaga
Waren Gonzaga - avatar
+ 2
the a should loop from 20 to 32 and b should loop from 3 to 9
10th Apr 2017, 6:04 PM
Waren Gonzaga
Waren Gonzaga - avatar
+ 2
Something like this? for (a>=3; a <= 9; a++) { if (someValue >= 14 + a * 2) { document.write ("output "+a+" ON"); } else { document.write ("output "+a+" OFF"); } }
10th Apr 2017, 10:25 PM
Shane
+ 1
@Tasha N.. you're right might be nested loop! but won't work.
10th Apr 2017, 6:00 PM
Waren Gonzaga
Waren Gonzaga - avatar
+ 1
Here's additional info: Loop the if else statement from different values. Check the javascript code for more info. I want to loop two values inside if-else I have used nested loop but that's horrible. It wont work. This code is for Arduino and I will convert it into C# if else statement the C# doesn't accept thr nested loop so how I can achieve it?
10th Apr 2017, 6:03 PM
Waren Gonzaga
Waren Gonzaga - avatar
0
yeah I know but I want to loop two different values inside if else statement please check the code.
10th Apr 2017, 5:51 PM
Waren Gonzaga
Waren Gonzaga - avatar