This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet45/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   41   42   43   44   45   46   47   48   ...   69
Bog'liq
PHP

Flow-Control Statements
|
53
This program adds the numbers from 1 to 10 using a
for
loop:
$total = 0;
for ($i= 1; $i <= 10; $i++) {
$total += $i;
}
Here’s the same loop using the alternate syntax:
$total = 0;
for ($i = 1; $i <= 10; $i++):
$total += $i;
endfor;
You can specify multiple expressions for any of the expressions in a
for
statement by
separating the expressions with commas. For example:
$total = 0;
for ($i = 0, $j = 0; $i <= 10; $i++, $j *= 2) {
$total += $j;
}
You can also leave an expression empty, signaling that nothing should be done for
that phase. In the most degenerate form, the
for
statement becomes an infinite loop.
You probably don’t want to run this example, as it never stops printing:
for (;;) {
echo "Can't stop me!
";
}
In
for
loops, as in
while
loops, you can use the
break
and
continue
keywords to end
the loop or the current iteration.
foreach
The
foreach
statement allows you to iterate over elements in an array. The two forms
of
foreach
statement are discussed in Chapter 5. To loop over an array, accessing
each key, use:
foreach (
$array
as
$current
) {
// ...
}
The alternate syntax is:
foreach (
$array
as
$current
):
// ...
endforeach;
To loop over an array, accessing both key and value, use:
foreach (
$array
as
$key => $value
) {
// ...
}
,ch02.15294 Page 53 Wednesday, March 13, 2002 11:42 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   41   42   43   44   45   46   47   48   ...   69




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish