1. Anasayfa
  2. Html

JavaScript While Döngüsü Örnekleri


1

Bundan önceki konumuzda For Döngüsü Kullanımı örneklerini paylaşmıştık şimdi ise JavaScript While Döngüsü örneklerini paylaşıyoruz.

1-0-100 arasındaki çift sayıları yazdıran program

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>http://www.bilisimogretmeni.com/</title>
    <script type="text/javascript">
        var i=0;
        while (i < 100) {
            i += 2;         
                document.write(i + "<br/>");         
        }
    </script>
</head>
<body>
</body>
</html>

2-Büyüyen Fontlarla ekrana Türkiye Yazan Program

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>http://www.bilisimogretmeni.com/</title>
    <script type="text/javascript">
        var i = 0;
        while (i < 10) {
            i++;
document.write("<span style='font-size:" + i + 5 + "px;'>Türkiye</span><br/>");
        }    
    </script>
</head>
<body>

</body>
</html>

3-Çift sayıları mavi tek sayıları sarı yazan program

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>http://www.bilisimogretmeni.com/</title>
    <script type="text/javascript">
        var i = 0;
        while (i < 100) {
            i++;
            if (i % 2 == 0) {              
        document.write("<span style='color:blue;'>" + i + "</span><br/>");
            }
            else {
                document.write("<span style='color:yellow;'>" + i + "</font><br/>");
            }
        }
    </script>
</head>
<body>

</body>
</html>

4-0-100 arasında 3 ve 5’e tam bölünen sayıların toplamını bulan program

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>http://www.bilisimogretmeni.com/</title>
    <script type="text/javascript">
        var toplam = 0;
        var i = 1;
        while (i <= 100) {
            if (i % 3 == 0 && i % 5 == 0) {
                if (i != 90) {
                    document.write(i + "+");
                }
                else {
                    document.write(i + "=");
                }
                toplam += i;
            }
            i++;
        }
        document.write(toplam);
    
    </script>
</head>
<body>

</body>
</html>

5-Kullanıcı çift sayı girene kadar sayı isteyen program

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>http://www.bilisimogretmeni.com/</title>
    <script type="text/javascript">
        var cevap;
        var toplam=0;
        while (cevap % 2 != 0) {
            cevap = prompt("Bir sayı Giriniz");
            toplam += parseInt(cevap);
        }
        toplam -= parseInt(cevap);
        document.write(toplam);
    </script>
</head>
<body>

</body>
</html>

6-Girilen Sayıların ortalaması çift olana kadar sayı isteyen program

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>http://www.bilisimogretmeni.com/</title>
    <script type="text/javascript">
        var ort = 1, toplam = 0, i = 0;
        var sayi;
        while (ort % 2 != 0) {        
            sayi = prompt("Bir sayı Girin");
            i++;
            toplam += parseInt(sayi);
            ort = toplam / i;
        }
        document.write("Sayıların Ortalaması =" + ort);
    </script>
</head>
<body>

</body>
</html>

7-Girilen sayı çift ise mesajları yan yana, tek ise alt alta tekrar eden program

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        var mesaj = prompt("Mesajı girin");
        var sayi = prompt("Tekrar sayısı");
        var i=0;
        if (parseInt(sayi) % 2 == 0) {
            while (i < sayi) {
                document.write(mesaj + " ");
                i++;
            }
        }
        else {
            while (i < sayi) {
                document.write(mesaj + "<br>");
                i++;
            }
        }
    </script>
</head>
<body>

</body>
</html>

8-Kullanıcıda şifre soran ve 3 hak sonunda kontrol eden program

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        var sifre = "123";
        var hak = 3;
        while (hak>0) {
            var mesaj = prompt("Şifreyi Girin");
            hak--;
            if (hak == 0) break;
            if (mesaj == sifre) {
                document.write("HOŞGELDİNİZ");
                break;
            }
            else {
                alert("Son " + hak + " hakkınız kaldı");
            }            
        }
        if (hak == 0) {
            document.write("İZİNSİZ GİREMEZSİNİZ");
        }
    </script>
</head>
<body>

</body>
</html>

Bu İçeriğe Tepkin Ne Oldu?
  • 9
    ba_ar_l_
    Başarılı
  • 2
    gayet_yi
    Gayet İyi
  • 2
    te_ekk_rler
    Teşekkürler
  • 4
    anlamad_m
    Anlamadım
  • 2
    yetersiz
    Yetersiz
İlginizi Çekebilir
Subscribe
Bildir
guest

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.

1 Yorum
Inline Feedbacks
View all comments
napim

Istedigimi bulamadim