java - While Loop not printing second command -
can tell me why second statement not print when counts gets below 4? first part prints "looping" part fine not print "no more loops". what's wrong?
enter code here public class scratchpad { public static void main(string[] args) { int xray = 7; while (xray > 4) { system.out.println("looping"); if (xray < 4) system.out.println("no more loops"); xray = xray - 1; } }
when xray
reaches value 4, while
loop finishes. that's why second statement doesn't printed.
if want printed 1 solution one:
public class scratchpad { public static void main(string[] args) { int xray = 7; while (xray >= 4){ system.out.println("looping"); if(xray <= 4) system.out.println("no more loops"); xray = xray-1; } } }
Comments
Post a Comment