This document discusses JavaScript loops (petlje) and provides examples of for loops. It explains the syntax of for loops with three statements - statement 1 is executed before the code block, statement 2 defines the condition, and statement 3 is executed after the code block. Examples are given to count from 0 to 9, do a 10 second countdown, print even house numbers from 100 to 120, and print the contents of an array forwards and backwards.
This document discusses JavaScript loops (petlje) and provides examples of for loops. It explains the syntax of for loops with three statements - statement 1 is executed before the code block, statement 2 defines the condition, and statement 3 is executed after the code block. Examples are given to count from 0 to 9, do a 10 second countdown, print even house numbers from 100 to 120, and print the contents of an array forwards and backwards.
This document discusses JavaScript loops (petlje) and provides examples of for loops. It explains the syntax of for loops with three statements - statement 1 is executed before the code block, statement 2 defines the condition, and statement 3 is executed after the code block. Examples are given to count from 0 to 9, do a 10 second countdown, print even house numbers from 100 to 120, and print the contents of an array forwards and backwards.
3 ✗ Da bi to mogli napraviti, potreban nam je drugi dio naredbe if, a to je else.
✗ Ako je uvjet istinit, izvršit će se prvi blok, a ako nije
istinit izvršit će se else blok.
pripremila Marijana Polić Kuko
4 pripremila Marijana Polić Kuko 5 ✗ Moramo nadodati još jedan uvjet.
pripremila Marijana Polić Kuko
6 Java Script PETLJE
pripremila Marijana Polić Kuko
Algoritam ponavljanja - Petlje ✗ Ovaj algoritam koristimo kada želimo ponavljati neki blok naredbi. ✗ Naredbe koje koristimo za primjenu algoritma ponavljanja u programiranju nazivamo petljama. ✗ Postoji više vrsta petlj, npr.: ✗ for ✗ while
pripremila Marijana Polić Kuko
For petlja ima sintaksu
for (statement 1; statement 2; statement 3) {
// code block to be executed } ✗ Statement 1 is executed (one time) before the execution of the code block. (jednom se izvršava prije bloka naredbi) ✗ Statement 2 defines the condition for executing the code block. (definira uvjet za izvršavanje bloka naredbi) ✗ Statement 3 is executed (every time) after the code block has been executed. (izvršava se uvijek nakon što se blok naredbi izvrši)
pripremila Marijana Polić Kuko
9 For petlja ✗ Zadatak 13: Štoperica Napravite program u JavaScriptu koji će ispisivati brojeve od 0 do 9.
pripremila Marijana Polić Kuko
10 pripremila Marijana Polić Kuko 11 For petlja ✗ Zadatak 14: Odbrojavanje Napravite program koji ispisuje zadnjih 10 sekundi za doček Nove godine. Zatim ispišite:”Sretna Nova Godina ”
pripremila Marijana Polić Kuko
12 pripremila Marijana Polić Kuko 13 For petlja ✗ Zadatak 15: parni U Ulici veselih klaunova netko je sa desne strane ulice obrisao parne kućne brojeve od 100 do 120. Napiši program koji će ispisati parne brojeve od 100 do 120 uključujući i 120.
pripremila Marijana Polić Kuko
14 pripremila Marijana Polić Kuko 15 For petlja i niz Zadatak 16: Ispis niza
Definirajmo niz radnih dana u tjednu.
Pomoću petlje ispiši elemente niza.
pripremila Marijana Polić Kuko
16 pripremila Marijana Polić Kuko 17 For petlja i niz Pomoću petlje ispiši elemente niza radnih dana u tjednu unatrag.