Java learning memo (while statement, do-while statement)

Since I started studying Java Silver, I will upload it as my memorandum. Since it is a rough memo, details are not described.

It is possible to omit {} in the while statement and do-while statement. However, note that if {} is omitted, only one sentence will be repeated. In the following example sentence, only "System.out.println (" 1st sentence ");" is repeated.

int cnt = 0; while(cnt++ < 10) System.out.println ("1st sentence"); System.out.println ("second sentence");

Also note that it is one sentence, not one line. Even if there is no line break, only the first sentence will be repeated if it is separated by ";".

Also, if you write two or more sentences when {} is omitted, a compile error will occur. int cnt = 0; do System.out.println ("1st sentence"); System.out.println ("second sentence"); while(cnt++ < 10);

Recommended Posts

Java learning memo (while statement, do-while statement)
[Java] for statement, while statement
Java learning memo (method)
Java learning memo (basic)
(Memo) Java for statement
Java learning memo (interface)
Java learning memo (inheritance)
Java learning memo (data type)
Java learning memo (logical operator)
Java learning memo (abstract class)
Java learning (0)
Java learning memo (creating an array)
(Learning memo) Java Level 2 measures: Question range
Java, for statement / while statement starting from beginner
java anything memo
Java Silver memo
For JAVA learning (2018-03-16-01)
Java learning day 5
java, maven memo
Java SE 7 memo
java anything memo 2
Java for statement
Java specification memo
java learning day 2
Java switch statement
Java pattern memo
java learning day 1
Java instruction execution statement
Java development environment memo
Java learning 2 (learning calculation method)
java learning (conditional expression)
[Java] for statement / extended for statement
java basic knowledge memo
Java Kuche Day memo
Java Learning (1)-Hello World
[Java ~ Method ~] Study memo (5)
java se 8 programmer Ⅰ memo
Java paid private memo
Learning memo 01 (forward / redirect)
JAVA learning history interface
Java (while statement) basic problem that beginners did first
[Java ~ Array ~] Study memo 4
java lambda expression memo
Learning memo when learning Java for the first time (personal learning memo)
Java lambda expression [memo]
[Java] Implicit inheritance memo
java competitive programming memo
Ruby Learning # 16 Return Statement
[Memo] Java Linked List
# 3 [Note] do ~ while statement
[Java Bronze] Learning memo (interface, static method, type conversion, etc.)
Learning Java framework # 1 (Mac version)
Java (WebSphere Application Server) memo [1]
Java basic learning content 7 (exception)
[Java] Variable name naming memo
Java memo (standard class) substring
Isn't the While statement evil?
JAVA learning history interface inheritance
12 Corresponds to the while statement
[Java] Basic statement for beginners
Java basic learning content 5 (modifier)