for loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

for loop

How to have increment of more than 1 in for loop?

2nd May 2019, 12:41 PM
Praveen Kumar Sutrave
4 Answers
+ 14
if i get you right you just simply need to increase increment count like this for(var i = 0; i < 5; i+= 2){}
2nd May 2019, 12:44 PM
r8w9
r8w9 - avatar
+ 3
Jason Mackjoo Java: Try this in the code playground and you will see that it is possible. for(int i = 0; i <= 100; i += 5){ System.out.println(i); } Btw. a lot of stuff is possible with a for loop, but normally we don't do it. For example: for(; ;){//some code} (an infinity for loop without values)
2nd May 2019, 3:03 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Instead I++ Used I +=2 Or I= i+2
2nd May 2019, 2:16 PM
Rahman Rezaie 🇦🇫
Rahman Rezaie 🇦🇫 - avatar
- 3
As far as i know, This cannot be done using for loop. Please check while loop.
2nd May 2019, 12:46 PM
Jason Mackjoo
Jason Mackjoo - avatar