0

I still did not understand the do while loops. Explain to me

Do while loops for java

21st Jun 2019, 11:11 AM
Muhammad Syamil Fahman Bin Che Samsurikhan
Muhammad Syamil Fahman Bin Che Samsurikhan - avatar
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.
21st Jun 2019, 11:22 AM
HNNX 🐿
HNNX 🐿 - avatar
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
21st Jun 2019, 2:04 PM
Matias
Matias - avatar