+ 1

Can we write if else statements in for loop??

To make source code easy.

17th Sep 2018, 1:46 PM
piyush damor
piyush damor - avatar
4 Answers
+ 6
int x = 0; for(;;){ if(x%2==0){System.out.println(x+" is even");} else{System.out.println(x+" is odd");} x++;}
17th Sep 2018, 1:56 PM
D_Stark
D_Stark - avatar
+ 5
piyush damor your welcome 😉👍
17th Sep 2018, 2:03 PM
D_Stark
D_Stark - avatar
+ 4
yes, of course you can. you can write else statements any time it follows an if statement
17th Sep 2018, 1:49 PM
J.G.
J.G. - avatar
+ 2
Tysm D_stark to elaborate it
17th Sep 2018, 1:58 PM
piyush damor
piyush damor - avatar