Can we write for loop in this way" for(intialization: expression)" (in java) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we write for loop in this way" for(intialization: expression)" (in java)

27th May 2019, 1:40 PM
Gangadhar N
Gangadhar N - avatar
4 Answers
+ 3
It is an enhanced for loop. int array: for(int i: arr){ //some code } String array: for(String s: arr){ //some code }
27th May 2019, 2:03 PM
Denise Roßberg
Denise Roßberg - avatar
27th May 2019, 2:04 PM
Denise Roßberg
Denise Roßberg - avatar
0
Which language are you using? In C# you can do it like this: for(initialization; expression;) { statements; increment; (optional) }
27th May 2019, 1:51 PM
Trigger
Trigger - avatar
0
Depends on the language. In most languages you can skip some parts of the for loop, for example: for(int i=0;i<10;) Here you skip the increment part, also you can skip initialization for(;i<0;i++)
27th May 2019, 1:53 PM
Andres0b0100
Andres0b0100 - avatar