Google Translate

While, Do - While dalam Java

A. While

Bentuk umum:
while (termination) {
body;
}


Bagian pada body akan terus menerus dieksekusi selama pernyataan termination menghasilkan true.

Contoh Syntax
class WhileDemo {
public static void main(String[] args){
int count = 1;
while (count < 11) {
System.out.println("Count is:
" + count);
count++;
}
}
}


b. do-while
Bentuk umum:
do {
body;
} while (termination);


Hampir sama dengan while, hanya di sini pemeriksaan terhadap pernyataan termination dilakukan di akhir perulangan, yang berarti perulangan pada body akan dieksekusi sekurang‐kurangnya sekali meskipun pernyataan termination bernilai false.

Contoh Syntax:
class DoWhileDemo {
public static void main(String[] args){
int count = 1;
do {
System.out.println("Count is: " + count);
count++;
} while (count <= 11);
}
}
Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© ILMU TEKNIK INFORMATIKA
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0
Posts RSSComments RSS
Back to top