Operasi pengulangan atau iterasi dalam java terdiri dari 3 statemen yaitu: (1) for, (2) while, dan (3) do while. ketiga statemen inilah yang dinamakan dengan loop, dimana loop sendiri secara berulang mengeksekusi sehimpunan intruksi sampai kondisi terminasi terpenuhi.
For
For sering disebut loop, karena digunakan untuk proses looping atau pengulangan. Bentuk penulisannya yaitu:
for (inisialisasi; kondisi; penaikan_penurunan){
pernyataan
}
public class DemoFor {
public static void main(String args[]) {
int n;
for(n=10; n>0; n--)
System.out.println("nomor " + n);
}
}
Hasilnya:
nomor 10
nomor 9
nomor 8
nomor 7
nomor 6
nomor 5
nomor 4
nomor 3
nomor 2
nomor 1
While
While digunakan untuk melakukan prose pengulangan suatu blog pernyataan selama kondisi bernilai true.
Bentuknya:
while (kondisi) {
pernyataan
}
contoh:
public class DemoWhile {
public static void main(String args[]) {
int n = 10;
while(n > 0) {
System.out.println("nomor " + n);
n--;
}
}
}
Hasilnya:
nomor 10
nomor 9
nomor 8
nomor 7
nomor 6
nomor 5
nomor 4
nomor 3
nomor 2
nomor 1
do while
do-while digunakan untuk melakukan prose pengulangan suatu blog pernyataan selama kondisi bernilai true. Pernyataan dalam blok paling tidak dieksekusi satu kali.
Bentuknya:
do {
pernyataan
}
while (kondisi);
Contoh:
public class DemoDoWhile {
public static void main(String args[]) {
int n = 10;
do {
System.out.println("nomor " + n);
n--;
} while(n > 0);
}
}
hasilnya:
nomor 10
nomor 9
nomor 8
nomor 7
nomor 6
nomor 5
nomor 4
nomor 3
nomor 2
nomor 1

CCFB0C0B94
ReplyDeleteGörüntülü Sex
Görüntülü Show
Cam Şov
8A350ED143
ReplyDeleteTakipçi Satın Al
Abone Hilesi
Backlink Satın Al
ReplyDeleteIn our entertainment options, you can find a variety of performances to enjoy. For those interested in exclusive experiences, the ücretli show offers a unique opportunity to see talented artists up close. Whether you're a fan of live music or theatrical acts, there's something for everyone. Don't miss out on this special experience that promises unforgettable moments.
AC0EE1A32A
ReplyDeleteMany online resources are available for digital creators seeking to enhance their skills. For comprehensive tutorials and community support, you can visit https://dtfhub.com. It's a valuable platform for staying updated with the latest trends and tools in the industry. Exploring such sites can significantly improve your workflow and creativity.