+ 1

For loop

Can someone please explain this 'for loop' statement and how and when to use it? I don't understand it. I get the while loop statement, but the for loop now is an issue for me.

21st Dec 2024, 9:14 PM
Ella
Ella - avatar
1 Respuesta
+ 6
Ella let x = 0 while (x < [ a known number ] here we are going to say 18) { Do something... x += 1; } for (int x = 0: x < 18; x++) { Do something... } These two literally are performing the same ... But typically you use the for loop when you know how many times you want to repeat the code or need a concise loop for simple iterations.
21st Dec 2024, 9:59 PM
BroFar
BroFar - avatar