0

how to convert the while loop to for loop??

3rd Jun 2017, 11:56 PM
fadi alshariti
fadi alshariti - avatar
3 Answers
+ 8
What language do you use? Plz specify your language. This is JavaScript Version... // While Loop var i = 0, res = 0; while (i < 5) { res++; i++; } // For Loop var i = 0, res = 0; for (; i < 5; i++) { res++; }
4th Jun 2017, 1:48 AM
김정제(Legacy)
김정제(Legacy) - avatar
+ 2
// for loop for (int i = 0; i < 10; i++){ // do somthing } // while loop int i = 0; while (i < 10){ // do somthing i++; } hope that helps
4th Jun 2017, 12:18 AM
sumAB
sumAB - avatar
+ 2
while (CONDITION) { ... } --> for (; CONDITION; ) { ... } But a for loop like that is awful.
4th Jun 2017, 5:21 AM
Tamás Barta
Tamás Barta - avatar