0
I still did not understand the do while loops. Explain to me
Do while loops for java
2 ответов
+ 1
Do while loop will execute at least once even if condition isn't met.
For example, you take user input
Scanner sc = new Scanner(System.in)
int x = Integer.ParseInt(sc.nextLine());
do {
System.out.println("print this out no matter what");
}
while( x < 5){
System.out.println("user number is smaller than 5");
}
Even if user sets number below 5, code will run.
0
Do {
Repeat this until condition is false
} while (condition)
Example:
Int i = 0;
Do {
System.out.println(i);
i++;
} while (i > 5)
So that will repeat 'till 'i' is greater than 5