Syntax of while loop in Java?
int i = 1;
while (i <= 5) {
System.out.println(i);
i++;
}
if-else Syntax:
if (condition) {
// statements if condition is true
} else {
// statements if condition is false
}
if-else & while loop both: syntax
int i = 1;
while (i <= 5) {
if (i % 2 == 0) {
System.out.println(i + " is even");
} else {
System.out.println(i + " is odd");
}
i++;
}
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.