Zobrazit příspěvky

Tato sekce Vám umožňuje zobrazit všechny příspěvky tohoto uživatele. Prosím uvědomte si, že můžete vidět příspěvky pouze z oblastí Vám přístupných.


Příspěvky - bebotax655

Stran: [1]
1
Vývoj / Re:If bez curly brackets?
« kdy: 19. 06. 2025, 12:37:00 »
Vzdy pouzivat curly brackets!

Kód: [Vybrat]
<script>

    function testWithBraces(a, b) {
        if (a == b) {
            for (let i = 0; i < 3; i++) {
                console.log("With braces: i =", i);
                console.log("This line always runs!");
            }
        }
    }

    function testWithoutBraces(a, b) {
        if (a == b)
            for (let i = 0; i < 3; i++)
                console.log("Without braces: i =", i);
                console.log("This line always runs!");
    }

    testWithBraces(5, 5);
    // With braces: i = 0
    // This line always runs!
    // With braces: i = 1
    // This line always runs!
    // With braces: i = 2
    // This line always runs!

    testWithBraces(5, 6);
    // Nothing

    testWithoutBraces(5, 5);
    // Without braces: i = 0
    // Without braces: i = 1
    // Without braces: i = 2
    // This line always runs!

    testWithoutBraces(5, 6);
    // This line always runs!

</script>

Stran: [1]