Anasayfa Java Dili For Döngüsü

Java Dili For Döngüsü

Okan

Döngüler, bir işlemin belli bir koşul altında tekrar edilmesi için kullanılır. For döngüsü, java programlama dilinde sıklıkla kullanılan döngülerden birisidir.

Java programlama dilinde:

  • For Döngüsü
  • While Döngüsü
  • Do-While Döngüsü

olmak üzere 3 farklı döngü çeşidi vardır. Bu bölümde for döngülerini inceleyeceğiz. Diğer döngü çeşitleri için Java Dili While ve Do-While Döngüleri sayfasını ziyaret edebilirsiniz.

FOR DÖNGÜSÜ

For döngüsü, en çok kullanılan döngülerden birisidir. Bir koşula bağlı olarak, belirli bir sayıda ve bir koşul sağlandığı süre boyunca tekrarlanan döngüdür.

Bu dersimizde temel for döngüsünü inceleyeceğiz. Birde Java 5.0 sıfır ile gelen enhanced for loop dediğimiz gelişmiş for döngüsü vardır. Diğer dillerde genellikle foreach döngüsü olarak adlandırılırlar. Bu döngüleri Java Dili Arraylist bölümünde anlatacağım.

Şimdi temel bir for döngüsünün genel yapısını inceleyelim.

for(sayac; kosul; sayac artısı)
{
komut1;
komut2;
..
..
}

Sayaç: Adından da anlaşıldığı üzere döngünün kaç defa çalıştığını gösterir. Sayaç daha önceden de tanımlanabilir.

int i = 0;
for(; i < 10; i++)
{
komut1;
komut2;
...
...
}

Yukarıdaki ‘i’ değişkenini yani sayacı tanımladığımız için for döngüsünün içindeki sayaç kısmını boş bırakıyoruz.

Koşul: Döngünün koşulunu kontrol eder ve koşul sağlandığı sürece döngü çalışmaya devam eder.

Sayaç artışı: Bu bölümde ise sayacın artışını veya azalışını belirleriz. Arttırma ve azaltma işlemlerin detaylı anlatımı için Java Dili Operatörler sayfasında arttırma ve azaltma operatörlerini inceleyebilirsiniz.

Şimdi de for döngüsünü kullanarak basit bir örnek yapalım.

package kodbloklari.com;

public class fordongusu {
	public static void main(String[] args) {
		
		for(int i = 0; i < 10; i++)
		{
			System.out.println("KOD BLOKLARI");
		}
	}
}

Programın içerisinde bir yazıyı 10 defa yazdırmak istiyorsak, bunun için 10 defa System.out.println() metotudunu kullanmamıza gerek yok. Yukarıdaki kodda da gördüğünüz gibi bunu 2 satırlık basit bir for döngüsü ile gerçekleştirebiliriz.

Yukarıdaki kod kısmında önce sayacı tanımladık ve 0′ dan başlattık. Daha sonra program koşul sağlandığı için devam etti, değeri 1 arttırıldı ve döngünün içerisindeki komutu çalıştırdı. Sonrasında şart sağlanmadığı ( i = 10) süreye kadar döngü devam etti. Böylece döngü 10 defa çalışmış oldu.

Kodun ekran çıktısı şu şekildedir:

for döngüsü

For döngüsünün en basit hali bu şekildedir.

FOR Döngüsüyle Faktöriyel Hesabı

Şimdi de For döngüsünü kullanarak faktöriyel hesaplayan bir program yazalım.

Faktöriyel: 1’den kendisine kadar olan sayıların çarpımına denir. ( 5! = 5.4.3.2.1)

Programın kodu aşağıdaki gibidir:

package kodbloklari.com;

import java.util.Scanner;

public class faktoriyel {
	
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int faktoriyel = 1;
		int sayi;
		
		System.out.print("Bir sayı giriniz: ");
		sayi = scan.nextInt();
		
		for(int i = 1; i <= sayi; i++)
		{
			faktoriyel *= i;
			//System.out.println(i + "! = " + faktoriyel); // girilen sayıyı kadar olan faktoriyel
		}
		System.out.println(sayi + "! = " + faktoriyel);
	}
}

Burada döngü değişkenini 1’den başlatıp girdiğimiz sayıya kadar döndüreceğiz. Döngü her döndüğünde elde ettiğimiz sayıyı çarpacağız.

Girilen sayıya kadar olan tüm sayıların faktöriyelini versin istiyorsanız 19.satırdaki açıklama satırını kaldırabilirsiniz.

Kodun ekran çıktısı şu şekildedir:

for-döngüsü-2

For döngüsünü kullanarak çok fazla örnek yapabiliriz. Konuyu örnekler yaparak daha iyi kavramak için  Java Dili Örnekleri sayfasını inceleyebilirsiniz.

102 Yorum

vorbelutr ioperbir 24 Haziran 2023 - 00:33

Thanks for sharing excellent informations. Your web-site is very cool. I’m impressed by the details that you?¦ve on this web site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my friend, ROCK! I found simply the info I already searched all over the place and just could not come across. What an ideal web-site.

Cevapla
http://mobileautodetailingkc.com 11 Ağustos 2023 - 23:41

Major thanks for the blog. Much obliged.

Cevapla
Bsectg 14 Ağustos 2023 - 02:23

buy fenofibrate cheap where can i buy tricor oral fenofibrate

Cevapla
Asalnh 18 Ağustos 2023 - 12:18

tadalafil 5mg pill sildenafil 50mg without prescription purchase viagra sale

Cevapla
Wnntzl 20 Ağustos 2023 - 17:01

zaditor order purchase sinequan imipramine 75mg pill

Cevapla
Jkzeqs 21 Ağustos 2023 - 03:40

purchase minoxytop solution purchase cialis online cheap new ed drugs

Cevapla
rare sports cards 21 Ağustos 2023 - 09:55

Thank you, I have just been searching for information approximately this subject for a long time and yours is the best I’ve found out till now. However, what concerning the bottom line? Are you certain concerning the supply?

Cevapla
Cesfilm 22 Ağustos 2023 - 04:09

Ahsoka Tano, introduced to fans through the beloved Star Wars animated series “Star Wars: The Clone Wars,” left the Jedi Order at the end of the show’s fifth season. Her journey continued in the follow-up series “Star Wars Rebels” and in other expanded universe media. However, it was in the pages of the “Ahsoka” novel by E.K. Johnston that the story of her white lightsabers was first touched upon.

Cevapla
Ylubfq 23 Ağustos 2023 - 15:05

buy precose generic buy acarbose 50mg sale griseofulvin ca

Cevapla
Tfmcfj 23 Ağustos 2023 - 19:05

aspirin over the counter buy levofloxacin sale imiquimod for sale online

Cevapla
Smart Contract Tool 24 Ağustos 2023 - 12:27

you’re really a good webmaster. The site loading speed is amazing. It seems that you are doing any unique trick. Furthermore, The contents are masterwork. you’ve done a fantastic job on this topic!

Cevapla
Fzrtlm 27 Ağustos 2023 - 02:41

melatonin 3 mg us purchase norethindrone sale danazol 100 mg uk

Cevapla
Wfycli 28 Ağustos 2023 - 05:09

dipyridamole cost brand dipyridamole 25mg pravachol order

Cevapla
Kaxwif 29 Ağustos 2023 - 17:40

buy dydrogesterone 10 mg online order jardiance online cheap order jardiance 10mg online cheap

Cevapla
Azwbkv 1 Eylül 2023 - 12:06

etodolac 600mg drug brand monograph 600mg pletal generic

Cevapla
Mac Pro Tricks 1 Eylül 2023 - 12:22

Mac Pro Tricks is an integrated news site covering all the news from all over the world, with a new vision that covers all the news as it happens from our different sources.

Cevapla
Crucible Institute 1 Eylül 2023 - 12:22

Crucible Institute – Arab Breaking News

Cevapla
Xiiafw 1 Eylül 2023 - 14:35

fludrocortisone 100mcg uk cost loperamide 2mg imodium for sale

Cevapla
Oxuxap 4 Eylül 2023 - 14:39

prasugrel pills cost tolterodine 1mg purchase detrol online

Cevapla
Dkrwae 6 Eylül 2023 - 05:44

pyridostigmine tablet rizatriptan 5mg ca maxalt 5mg pills

Cevapla
Gjkasn 7 Eylül 2023 - 14:54

buy cheap ferrous actonel order betapace 40mg uk

Cevapla
Wpdahc 10 Eylül 2023 - 13:34

xalatan medication buy xalatan no prescription buy rivastigmine 6mg

Cevapla
Mzcmkd 10 Eylül 2023 - 14:48

vasotec tablet lactulose uk buy duphalac bottles

Cevapla
Davidcheva 10 Eylül 2023 - 22:44

Absolutely! Finding info portals in the UK can be awesome, but there are numerous resources accessible to help you espy the perfect identical for the sake of you. As I mentioned in advance, conducting an online search with a view https://thewheelmedics.co.uk/wp-content/pgs/how-old-is-linsey-davis-abc-news.html “UK news websites” or “British intelligence portals” is a great starting point. Not only purposefulness this give you a encyclopaedic shopping list of report websites, but it intention also afford you with a improved pact of the current communication landscape in the UK.
On one occasion you obtain a file of imminent news portals, it’s critical to evaluate each anyone to shape which upper-class suits your preferences. As an example, BBC News is known in place of its objective reporting of information stories, while The Keeper is known representing its in-depth criticism of bureaucratic and social issues. The Independent is known for its investigative journalism, while The Times is known in search its affair and finance coverage. Not later than entente these differences, you can select the information portal that caters to your interests and provides you with the newsflash you want to read.
Additionally, it’s usefulness all in all close by scuttlebutt portals because specific regions within the UK. These portals lay down coverage of events and good copy stories that are akin to the area, which can be firstly accommodating if you’re looking to hang on to up with events in your close by community. In place of occurrence, local communiqu‚ portals in London include the Evening Standard and the Londonist, while Manchester Evening Hearsay and Liverpool Repercussion are hot in the North West.
Overall, there are tons statement portals accessible in the UK, and it’s high-level to do your digging to see the one that suits your needs. By evaluating the unconventional news programme portals based on their coverage, dash, and editorial perspective, you can select the individual that provides you with the most relevant and captivating info stories. Meet luck with your search, and I ambition this bumf helps you come up with the just right news portal inasmuch as you!

Cevapla
Kfxlwa 13 Eylül 2023 - 23:22

buy premarin 600 mg online cost premarin 600 mg buy sildenafil 50mg pill

Cevapla
Mvbpvg 15 Eylül 2023 - 06:15

prilosec 10mg ca montelukast generic buy lopressor pills

Cevapla
Epbzan 16 Eylül 2023 - 01:49

buy generic tadalafil cialis 20mg over the counter viagra for sale

Cevapla
Uwigff 16 Eylül 2023 - 14:41

buy telmisartan generic plaquenil pill order generic molnupiravir 200mg

Cevapla
Ckeblu 18 Eylül 2023 - 23:51

purchase cenforce generic buy aralen 250mg generic buy chloroquine generic

Cevapla
jessicaalex 19 Eylül 2023 - 13:13

I can’t believe focusing long enough to research; much less write this kind of article. You’ve outdone yourself with this material without a doubt. It is one of the greatest contents. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it . This is a great article, Given such a great amount of information in it, this kind of articles keeps the client’s enthusiasm for the site, and continue sharing more … write my assignment Thanks for sharing great information. It is nice to read such high-quality content. Thanks for the post

Cevapla
Ikmqte 19 Eylül 2023 - 15:38

buy provigil 200mg generic buy provigil 200mg deltasone order online

Cevapla
Vmwooc 22 Eylül 2023 - 14:57

accutane 20mg usa buy amoxicillin 1000mg online cheap order azithromycin 500mg sale

Cevapla
Pgevug 22 Eylül 2023 - 19:51

buy generic omnicef online cost prevacid order lansoprazole 15mg pill

Cevapla
Klpmik 24 Eylül 2023 - 18:36

azithromycin buy online azipro 250mg usa neurontin 100mg usa

Cevapla
Zjrxlm 26 Eylül 2023 - 15:05

lipitor 10mg price brand albuterol 100mcg buy amlodipine 5mg pill

Cevapla
Xkzrqa 27 Eylül 2023 - 00:33

online casino gambling lasix 40mg oral buy lasix 40mg

Cevapla
Iujomw 28 Eylül 2023 - 23:27

play poker online free best no deposit free spins purchase albuterol without prescription

Cevapla
Iibddk 29 Eylül 2023 - 09:45

protonix 20mg ca buy phenazopyridine pill order pyridium 200mg for sale

Cevapla
Yigbye 30 Eylül 2023 - 12:44

free poker online order generic stromectol 6mg ivermectin 5 mg price

Cevapla
Absqzk 2 Ekim 2023 - 04:44

online blackjack free free slot games online buy synthroid pills

Cevapla
Igchnr 2 Ekim 2023 - 17:17

amantadine for sale online buy symmetrel 100mg generic purchase dapsone sale

Cevapla
Quibir 3 Ekim 2023 - 21:31

order clomid generic generic isosorbide cost azathioprine 25mg

Cevapla
Awrinn 5 Ekim 2023 - 09:53

medrol 8 mg tablets purchase triamcinolone pills cheap triamcinolone 10mg

Cevapla
Xqbddv 5 Ekim 2023 - 10:30

buy generic levitra 20mg buy levitra 20mg without prescription order generic tizanidine 2mg

Cevapla
Yongcf 7 Ekim 2023 - 07:30

dilantin 100 mg for sale buy dilantin without a prescription order oxybutynin 2.5mg without prescription

Cevapla
Luyoxt 8 Ekim 2023 - 02:33

purchase aceon for sale desloratadine 5mg drug order fexofenadine 120mg online cheap

Cevapla
flits 8 Ekim 2023 - 20:18

During the last 5 years, Amatic has gained more visibility on European markets and probably is going to continue doing that in 2021 So why not to transform this soft provider into an exclusive partner of your casino and beat the rivals? And with Softgaming’s “Slots Bundle” service it’s easier than ever! Just book a demo (it will take just a few clicks) and add the top slots from the 20 most popular soft providers into your casino’s portfolio. Fire and Ice slot has new features and designs of classic slot machines with well-thought-out but exact details. Amatic Industries games’ Fire and Ice slot have the gameplay to the intricate details that make for an outstanding casino. The best thing about this slot is the opportunities it gives players to win.
http://www.yiwukorea.com/bbs/board.php?bo_table=free&wr_id=6195
Also valid at Dreams casino | Royal Ace casino | Raging Bull casino 18+ only. Terms Apply, gamble responsibly. 18+ only. Terms Apply, gamble responsibly. RUBYSLOTS gives 30 free spins no deposit for Cubbe Time Travel Adventure to all new players that sign up a new account and Redeem the code CUBEE30 A 100% Sign Up bonus with a max bonus of $1000 and a wagering requirement of 30x(b&d) on Slots and Parlor Games.Code: RUBY100Percentage play-through by game: Having a great time at Ruby Slots Casino and need to make a real money deposit in order to claim another free chip? Then, we recommend this welcome bonus. The RUBY250 coupon code can only be used alongside your first deposit ever at the casino. The player from Finland is experiencing difficulties verifying his account. According to the information provided by the casino, the player breached the rules of bonuses with playing on roulette, which is excluded from bonuses. Hence, we were forced to reject this complaint.

Cevapla
Fwnofc 9 Ekim 2023 - 08:05

cheap ozobax baclofen 10mg ca buy toradol generic

Cevapla
Yvyxsj 11 Ekim 2023 - 09:46

order generic baclofen 25mg purchase elavil online cheap toradol price

Cevapla
Aajopt 11 Ekim 2023 - 10:48

buy generic claritin for sale ramipril cheap dapoxetine pills

Cevapla
Orzapq 13 Ekim 2023 - 03:58

buy fosamax 70mg macrodantin 100 mg cost buy furadantin 100 mg sale

Cevapla
Fcobyv 15 Ekim 2023 - 14:21

buy inderal pills for sale inderal 20mg drug plavix 75mg us

Cevapla
Cyzldi 17 Ekim 2023 - 20:15

nortriptyline 25mg over the counter order methotrexate 5mg pills buy anacin for sale

Cevapla
Jiqhur 19 Ekim 2023 - 02:58

where can i buy amaryl purchase cytotec pill purchase etoricoxib without prescription

Cevapla
Oyxuey 19 Ekim 2023 - 23:59

coumadin 2mg sale coumadin generic order metoclopramide online

Cevapla
Qrhgeb 23 Ekim 2023 - 11:12

pepcid 20mg generic buy cozaar pills for sale purchase prograf pill

Cevapla
Nxwxot 26 Ekim 2023 - 14:59

buy nexium paypal purchase topamax online cheap topiramate 100mg ca

Cevapla
Oekodp 26 Ekim 2023 - 19:55

astelin sale order astelin 10 ml online cheap order avapro 300mg pill

Cevapla
Gwyhly 29 Ekim 2023 - 01:11

imitrex 25mg pills buy dutasteride pill buy cheap generic dutasteride

Cevapla
Xluodw 29 Ekim 2023 - 17:53

allopurinol 300mg without prescription zyloprim 100mg cost buy crestor 10mg for sale

Cevapla
Knjgmv 30 Ekim 2023 - 11:00

ranitidine 150mg for sale order meloxicam without prescription celebrex over the counter

Cevapla
Zacnmu 31 Ekim 2023 - 17:11

buspar 5mg canada cordarone 200mg uk cordarone 200mg without prescription

Cevapla
Fbbshj 1 Kasım 2023 - 14:13

purchase flomax sale zocor for sale online buy simvastatin 20mg online

Cevapla
Kufrkb 3 Kasım 2023 - 00:36

order motilium generic order coreg 25mg online sumycin 250mg us

Cevapla
Eirtta 3 Kasım 2023 - 12:20

buy aldactone online valacyclovir online order finpecia order

Cevapla
Dubyuq 4 Kasım 2023 - 23:07

pre written essays for sale write my thesis pay for essay

Cevapla
Vwfrcj 5 Kasım 2023 - 10:05

oral fluconazole 100mg buy generic cipro over the counter buy ciprofloxacin 1000mg online

Cevapla
Nxsuqj 6 Kasım 2023 - 23:16

order sildenafil 50mg sale brand sildalis order estrace generic

Cevapla
Dssepa 7 Kasım 2023 - 05:52

order flagyl 200mg online metronidazole 400mg without prescription keflex 125mg drug

Cevapla
Uikfbo 8 Kasım 2023 - 21:03

buy lamotrigine 200mg for sale buy prazosin 1mg generic buy mebendazole generic

Cevapla
Pxdzsl 9 Kasım 2023 - 01:00

cleocin 150mg uk buy clindamycin without prescription blue pill for ed

Cevapla
Nddsfd 10 Kasım 2023 - 18:50

buy generic nolvadex betahistine 16 mg pill buy rhinocort

Cevapla
Grgtpt 10 Kasım 2023 - 19:56

tretinoin cream price order avana online order generic stendra

Cevapla
Rsavbs 12 Kasım 2023 - 14:55

ceftin medication careprost online order buy robaxin 500mg generic

Cevapla
Bzuzqq 12 Kasım 2023 - 21:34

cost tadacip 10mg tadalafil 10mg over the counter indomethacin online

Cevapla
Vpydin 14 Kasım 2023 - 20:04

buy trazodone 50mg buy generic desyrel 100mg clindamycin online

Cevapla
Vxoyoo 16 Kasım 2023 - 10:55

where to buy aspirin without a prescription best real money casino poker online play

Cevapla
Oepswp 16 Kasım 2023 - 11:27

buy terbinafine 250mg without prescription purchase terbinafine generic live casino slots online

Cevapla
Qknjei 18 Kasım 2023 - 05:47

i need help with my essay slot machines gamble poker online

Cevapla
Gndjum 18 Kasım 2023 - 13:22

help me write a research paper write a review order cefixime 100mg generic

Cevapla
Alxzlr 20 Kasım 2023 - 05:15

buy rocaltrol 0.25 mg generic tricor 200mg tablet tricor price

Cevapla
Aajjo 20 Kasım 2023 - 14:47

Aajjo Business Solutions Private Limited stands as India’s premier digital marketplace, spearheading innovation and connectivity across diverse industries. Renowned for its cutting-edge solutions Aajjo B2B Platform
seamlessly facilitates business transactions, fostering growth and collaboration. With a commitment to excellence, it has emerged as the foremost choice for businesses seeking a dynamic and efficient marketplace experience.

Cevapla
Fockck 20 Kasım 2023 - 15:18

buy amoxicillin 500mg generic how to buy amoxicillin generic biaxin 250mg

Cevapla
Dtpqto 22 Kasım 2023 - 00:49

acne treatment recommended by dermatologists trileptal pills order trileptal 600mg generic

Cevapla
peacocktv.com 22 Kasım 2023 - 13:37

ThankYou For Sharing Such An Great Post – Unlock the Power of Premium Content Watch Now
peacocktv.com/tv

Cevapla
Ovhizy 22 Kasım 2023 - 14:18

buy catapres no prescription antivert drug order spiriva pill

Cevapla
Qnqbgw 23 Kasım 2023 - 17:53

uroxatral 10mg price costco canada cold and sinus percription medicine for stomach cramps

Cevapla
Tuvuwe 24 Kasım 2023 - 12:00

buy minocin 100mg pill minocycline 50mg sale buy requip tablets

Cevapla
Ikotxo 25 Kasım 2023 - 12:06

strong sleeping pills for sale sleep prescription online online prescription weight loss programs

Cevapla
Dktaaf 26 Kasım 2023 - 14:36

femara 2.5mg tablet order albenza 400mg generic abilify drug

Cevapla
Kbmykz 27 Kasım 2023 - 05:23

fda approved smoking cessation products best pills for arthritis pain alphabetical list of pain medications

Cevapla
Bmvlqn 28 Kasım 2023 - 12:38

buy provera 5mg generic order biltricide 600mg online cheap cheap hydrochlorothiazide

Cevapla
Pcavlf 28 Kasım 2023 - 22:58

best antiviral drugs inhalers for asthma buy online drugs for type two diabetes

Cevapla
Ffjbxq 29 Kasım 2023 - 19:48

buy periactin 4 mg generic brand fluvoxamine 50mg nizoral oral

Cevapla
Hdydux 30 Kasım 2023 - 02:41

pictures of fungus on skin buy medication for herpes online blood pressure medications by name

Cevapla
Zujwqf 1 Aralık 2023 - 14:42

cymbalta 20mg drug cymbalta 20mg pills provigil where to buy

Cevapla
Ybgsfv 1 Aralık 2023 - 19:51

best for ulcers pain and wounds fast best medicine for svt gram negative bacilli uti treatment

Cevapla

Yorum Yap

Bu web sitesi deneyiminizi geliştirmek için çerezler kullanmaktadır. Kabul Et Tamamını Oku

Gizlilik Politikası