SlideShare a Scribd company logo

9_PETLJE.pptx

petlje opid djela

1 of 8
Download to read offline
1
PROGRAMIRANJE
2
BASIC
Kad je potrebno, zadatim uslovom, neku proceduru ponavljati određen broj puta tada
koristimo petlje.
 Naredba FOR predstavlja početak, a naredba NEXT kraj FOR-NEXT petlje .
 Sve između ove dvije naredbe je "niz naredbi koji se ponavlja".
 Naredba PRINT x, prvi puta ispisuje 1 (jer je početna vrijednost 1 a krajnja 10)
 Naredba NEXT, povećava vijednost varijable za 1 i vraća naredbi PRINT pa
je slijedeći ispis 2, 3, 4, 5... i na kraju10.
Naredba FOR – NEXT (za - sljedeći)
Sintaksa naredbe ima oblik:
FOR brojač=početna vrijednost TO krajnja vrijednost
NEXT brojač
1
10 REM Ispisivanje brojeva od 1 do 30 sa
korakom 5
20 FOR x = 1 TO 30 STEP 5
PRINT x
30 NEXT x
50 END
6
11
21
16
26
PROGRAMIRANJE
3
BASIC
bn1 FOR brojač=početna vrijednost TO krajnja vrijednost STEP korak bn2 NEXT brojač
PROGRAMIRANJE
4
BASIC
10 REM Tablica mnozenja
20 FOR a = 1 TO 10 `Pocetak vanjske petlje
30 FOR b = 1 TO 10 `Pocetak unutrašnje petlje
40 c = a * b
50 IF c < 10 THEN PRINT " "; c; ELSE PRINT c;
60 NEXT b `Kraj unutrašnje petlje
70 PRINT
80 NEXT a `Kraj vanjske petlje
90 END
Program može sadržavati petlju u kojoj se odvija niz instrukcija, kao što smo opisali
u prethodnom primjeru.
Također, petlja može sadržavati tzv. "ugnježdenu" petlju.
Osnovna petlja se naziva , a "ugnježdena" .
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
PROGRAMIRANJE
5
BASIC
NIZOVI - indeksirane variajble
Nekada je potrebno upisati određeni skup podataka - niz.
Veličinu niza određujemo – dimenzioniramo naredbom DIM.
Sintaksa naredbe ima oblik:
bn DIM indeksirana promjenljiva (ili više njih)
10 REM Program za upis ocjena
20 DIM O(15)
30 FOR n = 1 TO 15
40 INPUT O(n)
50 NEXT n
60 END
? 2
? 4
? 3
? 5
? 4
Da bi izračunali uspjeh učenika treba upisati15 ocjena iz svih nastavnih predmeta.
Npr. Indeksiranoj varijabli možemo dodijeliti ime ocjene(15) ili O(15) ili x(15).
Indeksirana varijabla određena je imenom i indeksom - brojem upisanim
u zagradi.
? 5
? 5
? 5
? 5
? 4
? 5
? 4
? 5
? 5
? 4
PROGRAMIRANJE
6
BASIC
DIM O(3,14)
FOR n=1 TO 3
FOR m=1 TO 14
INPUT O(n,m)
NEXT m
NEXT n
END
DIM O(3,14,30)
FOR n=1 TO 3
FOR m=1 TO 14
FOR x=1 TO 30
INPUT O(n,m,x)
NEXT x
NEXT m
NEXT n
END
Primjer
dvodimenzionalnog niza
Primjer
trodimenzionalnog niza

Recommended

SLOM KOMUNIZMA U EUROPI.pptx kuna zlatica
SLOM KOMUNIZMA U EUROPI.pptx kuna zlaticaSLOM KOMUNIZMA U EUROPI.pptx kuna zlatica
SLOM KOMUNIZMA U EUROPI.pptx kuna zlaticaIsmarHukic2
 
ZAUSTAVIMO NASILJE.ppt nasilje u školama
ZAUSTAVIMO NASILJE.ppt nasilje u školamaZAUSTAVIMO NASILJE.ppt nasilje u školama
ZAUSTAVIMO NASILJE.ppt nasilje u školamaIsmarHukic2
 
RIJEKE U HRVATSKOJ.pptx rijejčni slivovi
RIJEKE U HRVATSKOJ.pptx rijejčni slivoviRIJEKE U HRVATSKOJ.pptx rijejčni slivovi
RIJEKE U HRVATSKOJ.pptx rijejčni slivoviIsmarHukic2
 
šarko - D.RAD.pptx
šarko - D.RAD.pptxšarko - D.RAD.pptx
šarko - D.RAD.pptxIsmarHukic2
 
druga_industrijska_revolucija.ppt
druga_industrijska_revolucija.pptdruga_industrijska_revolucija.ppt
druga_industrijska_revolucija.pptIsmarHukic2
 
Bizant__Europski_zapad_-_ponavljanje.pptx
Bizant__Europski_zapad_-_ponavljanje.pptxBizant__Europski_zapad_-_ponavljanje.pptx
Bizant__Europski_zapad_-_ponavljanje.pptxIsmarHukic2
 
prezentacija biro roditelji (1).pptx
prezentacija biro roditelji (1).pptxprezentacija biro roditelji (1).pptx
prezentacija biro roditelji (1).pptxIsmarHukic2
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

9_PETLJE.pptx

  • 1. 1
  • 2. PROGRAMIRANJE 2 BASIC Kad je potrebno, zadatim uslovom, neku proceduru ponavljati određen broj puta tada koristimo petlje.  Naredba FOR predstavlja početak, a naredba NEXT kraj FOR-NEXT petlje .  Sve između ove dvije naredbe je "niz naredbi koji se ponavlja".  Naredba PRINT x, prvi puta ispisuje 1 (jer je početna vrijednost 1 a krajnja 10)  Naredba NEXT, povećava vijednost varijable za 1 i vraća naredbi PRINT pa je slijedeći ispis 2, 3, 4, 5... i na kraju10. Naredba FOR – NEXT (za - sljedeći) Sintaksa naredbe ima oblik: FOR brojač=početna vrijednost TO krajnja vrijednost NEXT brojač
  • 3. 1 10 REM Ispisivanje brojeva od 1 do 30 sa korakom 5 20 FOR x = 1 TO 30 STEP 5 PRINT x 30 NEXT x 50 END 6 11 21 16 26 PROGRAMIRANJE 3 BASIC bn1 FOR brojač=početna vrijednost TO krajnja vrijednost STEP korak bn2 NEXT brojač
  • 4. PROGRAMIRANJE 4 BASIC 10 REM Tablica mnozenja 20 FOR a = 1 TO 10 `Pocetak vanjske petlje 30 FOR b = 1 TO 10 `Pocetak unutrašnje petlje 40 c = a * b 50 IF c < 10 THEN PRINT " "; c; ELSE PRINT c; 60 NEXT b `Kraj unutrašnje petlje 70 PRINT 80 NEXT a `Kraj vanjske petlje 90 END Program može sadržavati petlju u kojoj se odvija niz instrukcija, kao što smo opisali u prethodnom primjeru. Također, petlja može sadržavati tzv. "ugnježdenu" petlju. Osnovna petlja se naziva , a "ugnježdena" . 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100
  • 5. PROGRAMIRANJE 5 BASIC NIZOVI - indeksirane variajble Nekada je potrebno upisati određeni skup podataka - niz. Veličinu niza određujemo – dimenzioniramo naredbom DIM. Sintaksa naredbe ima oblik: bn DIM indeksirana promjenljiva (ili više njih) 10 REM Program za upis ocjena 20 DIM O(15) 30 FOR n = 1 TO 15 40 INPUT O(n) 50 NEXT n 60 END ? 2 ? 4 ? 3 ? 5 ? 4 Da bi izračunali uspjeh učenika treba upisati15 ocjena iz svih nastavnih predmeta. Npr. Indeksiranoj varijabli možemo dodijeliti ime ocjene(15) ili O(15) ili x(15). Indeksirana varijabla određena je imenom i indeksom - brojem upisanim u zagradi. ? 5 ? 5 ? 5 ? 5 ? 4 ? 5 ? 4 ? 5 ? 5 ? 4
  • 6. PROGRAMIRANJE 6 BASIC DIM O(3,14) FOR n=1 TO 3 FOR m=1 TO 14 INPUT O(n,m) NEXT m NEXT n END DIM O(3,14,30) FOR n=1 TO 3 FOR m=1 TO 14 FOR x=1 TO 30 INPUT O(n,m,x) NEXT x NEXT m NEXT n END Primjer dvodimenzionalnog niza Primjer trodimenzionalnog niza
  • 7. PROGRAMIRANJE 7 BASIC Naredba COLOR Naredba COLOR omogućava prikazivanje teksta u boji na ekranu i boju pozadine ekrana. Na raspolaganju imate šesnaest boja od 0 do 15, kao i boje sa dodatnim efektima od 16 do 31. 5 CLS 6 COLOR 2 ` Boja za programsku liniju 10 10 PRINT "Upisite jedan broj" 11 COLOR 3 ` Boja za programsku liniju 20 20 INPUT x 21 COLOR 5 ` Boja za programsku liniju 30 30 PRINT "UPISALI STE BROJ"; x 31 COLOR 14 ` Boja za programsku liniju 40 40 PRINT "BRAVO!" Upisite jedan broj ? 4 Upisali ste broj 4 Bravo BROJ BOJA BROJ BOJA 0 Crna 8 Siva 1 Plava 9 Svijetloplava 2 Zelena 10 Svijetlozelena 3 Modra 11 Svijetlomodra 4 Cvena 12 Svijetlocrvena 5 Ljubičasta 13 Svijetloljubičasta 6 Smeđa 14 Žuta 7 Bijela 15 Sjajno bijela
  • 8. PROGRAMIRANJE 8 BASIC 10 PRINT "Upisite jedan broj" 20 INPUT x 30 IF x > 20 THEN GOTO 10 40 FOR n = x TO 1 STEP -1 50 FOR m = 1 TO n 60 boja = 1 + INT(RND * 15) 70 COLOR boja : PRINT "**" 80 NEXT m 90 PRINT 100 NEXT n 110 END Upisite jedan broj ? 18