-2

please tell me if another way to show nonEquivalence of loops

for(int i = 0; i < 10; i++){    
    if (i % 2 == 0)    
            continue;    
    System.out.println(i);    
}

//non equivalent statement. is there any like this(without continue)   
int i = 0;    
while(i < 10){    
    if (i % 2 == 0)    
            continue;    
    System.out.println(i);
}
Cory Kleiser
  • 1,969
  • 2
  • 13
  • 26
M08ow
  • 1
  • 1
  • 1
  • I don't understand your question. Of course, your 2nd version is not equivalent to the 1st one, since i is never incremented. – Reinhard Männer Apr 28 '18 at 16:24
  • @Reinhard It is not equivalent even if there is increment( which I forgot) there. I am trying to show that while and for loops are not equivalent and wanted if there another like this. – M08ow May 01 '18 at 18:04
  • If you forgot a statement, please edit your question. – Reinhard Männer May 01 '18 at 21:32

1 Answers1

0

From what i gather from you code, you want to display only odd number in your loop. Try this

for(int i = 0; i < 10; i++){    
    if (i % 2 != 0)    
        System.out.println(i);    
}

Instead of finding when i is even and doing the continue statement, simply "reverse" the condition. The same goes for the while