0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Java学習メモ (while文、do-while文)

Last updated at Posted at 2019-08-04

Java Silverの勉強を始めたので、自分の忘備録としてUPします。
ざっくりとしたメモなので、詳細は記載してません。

while文、do-while文でも{}を省略することが可能である。
しかし、{}を省略した場合、繰り返されるのは1文だけなので注意すること。
以下の例文だと繰り返されるのは「System.out.println("1文目");」のみである。

int cnt = 0;
while(cnt++ < 10)
System.out.println("1文目");
  System.out.println("2文目");

1行ではなく、1文である点も要注意。
改行していなくても「;」で区切っていれば1文目しか繰り返しはされない。

また、{}を省略した際に2文以上記述するとコンパイルエラーになる。
int cnt = 0;
do
System.out.println("1文目");
  System.out.println("2文目");
while(cnt++ < 10);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?