SlideShare a Scribd company logo
Looping StatementLooping Statement
Chapter 5
MOHAMAD RAHIMI MOHAMAD
ROSMAN
IntroductionIntroduction
Looping statements in PHP are used to execute
the same block of code a specified number of
times.
◦ While
 loops through a block of code if and as long as a specified
condition is true
◦ do...while
 loops through a block of code once, and then repeats the
loop as long as a special condition is true
◦ For
 loops through a block of code a specified number of times
◦ Foreach
 loops through a block of code for each element in an array
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The while StatementThe while Statement
The while statement will execute a block
of code if and as long as a condition is
true.
while (condition)
code to be executed;
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The do...while StatementThe do...while Statement
The do...while statement will execute a block of
code at least once - it then will repeat the loop as
long as a condition is true.
Syntax
do
{
code to be executed;
}
while (condition);
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
 The following example will increment the value of i at
least once, and it will continue incrementing the
variable i as long as it has a value of less than 5:
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The for StatementThe for Statement
The for statement is used when you know
how many times you want to execute a
statement or a list of statements.
Syntax
for (initialization; condition; increment)
{
code to be executed;
}
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The for StatementThe for Statement
The for statement has three parameters.
The first parameter initializes variables
The second parameter holds the condition
The third parameter contains the increments
required to implement the loop
If more than one variable is included in the
initialization or the increment parameter, they
should be separated by commas.
The condition must evaluate to true or false.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
What is the result of the following code?
MOHAMAD RAHIMI MOHAMAD
ROSMAN
The foreach StatementThe foreach Statement
The foreach statement is used to loop
through arrays.
For every loop, the value of the current
array element is assigned to $value (and
the array pointer is moved by one) - so on
the next loop, you'll be looking at the next
element.
MOHAMAD RAHIMI MOHAMAD
ROSMAN
Syntax
foreach (array as value)
{
code to be executed;
}
MOHAMAD RAHIMI MOHAMAD
ROSMAN
ExampleExample
<html> <body>
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
}
?>
</body> </html>
MOHAMAD RAHIMI MOHAMAD
ROSMAN
What is the result of the following code?
ExerciseExercise
Looping
MOHAMAD RAHIMI MOHAMAD
ROSMAN
<?php
$id=array("2001","2002","2003","2004");
$name=array("Rahul","Yunos","Mubin","Anuar");
$class=array("3A","3B","3C","3D");
$cgpa=array("3.56","3.49","3.85","3.63");
echo "Last week, a student named ".$name[0].", with UiTM ID ".$id[0].", from class ".
$class[0]." with a CGPA of ".$cgpa[0]." has been choosen to represent our
university for a debate tournament";
echo "<br>";echo "<br>";
echo "Last week, a student named ".$name[1].", with UiTM ID ".$id[1].", from class ".
$class[1]." with a CGPA of ".$cgpa[1]." has been choosen to represent our
university for a debate tournament";
echo "<br>";echo "<br>";
echo "Last week, a student named ".$name[2].", with UiTM ID ".$id[2].", from class ".
$class[2]." with a CGPA of ".$cgpa[2]." has been choosen to represent our
university for a debate tournament";
echo "<br>";echo "<br>";
echo "Last week, a student named ".$name[3].", with UiTM ID ".$id[3].", from class ".
$class[3]." with a CGPA of ".$cgpa[3]." has been choosen to represent our
university for a debate tournament";
?>
Changes the following codes by using the looping functions

More Related Content

What's hot

Learn VbScript -String Functions
Learn VbScript -String FunctionsLearn VbScript -String Functions
Learn VbScript -String Functions
Nilanjan Saha
 
C Programming Loop
C Programming LoopC Programming Loop
C Programming Loop
Mahmudul Hasan
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb script
Nilanjan Saha
 
Loops
LoopsLoops
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1Jesus Obenita Jr.
 
TypeScript, Now.
TypeScript, Now.TypeScript, Now.
TypeScript, Now.
Suthep Sangvirotjanaphat
 

What's hot (10)

Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Learn VbScript -String Functions
Learn VbScript -String FunctionsLearn VbScript -String Functions
Learn VbScript -String Functions
 
C Programming Loop
C Programming LoopC Programming Loop
C Programming Loop
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb script
 
Loops
LoopsLoops
Loops
 
Loops
LoopsLoops
Loops
 
Python loops
Python loopsPython loops
Python loops
 
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1
 
TypeScript, Now.
TypeScript, Now.TypeScript, Now.
TypeScript, Now.
 

Viewers also liked

Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch casesMeoRamos
 
The Loops
The LoopsThe Loops
The Loops
Krishma Parekh
 
Loops
LoopsLoops
C++ loop
C++ loop C++ loop
C++ loop
Khelan Ameen
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
Himanshu Negi
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement_jenica
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
Sukrit Gupta
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structureJd Mercado
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
Sonya Akter Rupa
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
Hock Leng PUAH
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loopsbsdeol28
 
C language in hindi (cलेग्वेज इन हिंदी )
C language  in hindi (cलेग्वेज इन हिंदी )C language  in hindi (cलेग्वेज इन हिंदी )
C language in hindi (cलेग्वेज इन हिंदी )
Chand Rook
 
Overview of c language
Overview of c languageOverview of c language
Overview of c languageshalini392
 

Viewers also liked (20)

Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
 
The Loops
The LoopsThe Loops
The Loops
 
Loops
LoopsLoops
Loops
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loops c++
Loops c++Loops c++
Loops c++
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
Loops
LoopsLoops
Loops
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
 
Looping statement
Looping statementLooping statement
Looping statement
 
10. switch case
10. switch case10. switch case
10. switch case
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
C language in hindi (cलेग्वेज इन हिंदी )
C language  in hindi (cलेग्वेज इन हिंदी )C language  in hindi (cलेग्वेज इन हिंदी )
C language in hindi (cलेग्वेज इन हिंदी )
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 

Similar to Chapter 05 looping

Chapter 03 conditional statements
Chapter 03   conditional statementsChapter 03   conditional statements
Chapter 03 conditional statements
Dhani Ahmad
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
Niladri Karmakar
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllersmussawir20
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
MLG College of Learning, Inc
 
Decision and looping examples with php (WT)
Decision and looping examples with php (WT)Decision and looping examples with php (WT)
Decision and looping examples with php (WT)
kunjan shah
 
php basics
php basicsphp basics
php basics
Anmol Paul
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
ravi18011991
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
ravi18011991
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
Abu Bakar
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
zalatarunk
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
Nishant804733
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
NBACriteria2SICET
 
php-I-slides.ppt
php-I-slides.pptphp-I-slides.ppt
php-I-slides.ppt
SsewankamboErma
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
Deepak Rajput
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
Abdul Samad
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
MARELLA CHINABABU
 

Similar to Chapter 05 looping (20)

Chapter 03 conditional statements
Chapter 03   conditional statementsChapter 03   conditional statements
Chapter 03 conditional statements
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
 
Decision and looping examples with php (WT)
Decision and looping examples with php (WT)Decision and looping examples with php (WT)
Decision and looping examples with php (WT)
 
php basics
php basicsphp basics
php basics
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
 
php-I-slides.ppt
php-I-slides.pptphp-I-slides.ppt
php-I-slides.ppt
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
 

More from Dhani Ahmad

Strategic planning
Strategic planningStrategic planning
Strategic planning
Dhani Ahmad
 
Strategic information system planning
Strategic information system planningStrategic information system planning
Strategic information system planning
Dhani Ahmad
 
Opportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysisOpportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysisDhani Ahmad
 
Information system
Information systemInformation system
Information systemDhani Ahmad
 
Information resource management
Information resource managementInformation resource management
Information resource managementDhani Ahmad
 
Types of islamic institutions and records
Types of islamic institutions and recordsTypes of islamic institutions and records
Types of islamic institutions and records
Dhani Ahmad
 
Islamic information seeking behavior
Islamic information seeking behaviorIslamic information seeking behavior
Islamic information seeking behavior
Dhani Ahmad
 
Islamic information management
Islamic information managementIslamic information management
Islamic information management
Dhani Ahmad
 
Islamic information management sources in islam
Islamic information management sources in islamIslamic information management sources in islam
Islamic information management sources in islam
Dhani Ahmad
 
The need for security
The need for securityThe need for security
The need for security
Dhani Ahmad
 
The information security audit
The information security auditThe information security audit
The information security audit
Dhani Ahmad
 
Security technologies
Security technologiesSecurity technologies
Security technologies
Dhani Ahmad
 
Security policy
Security policySecurity policy
Security policy
Dhani Ahmad
 
Security and personnel
Security and personnelSecurity and personnel
Security and personnel
Dhani Ahmad
 
Secure
SecureSecure
Secure
Dhani Ahmad
 
Risk management ii
Risk management iiRisk management ii
Risk management ii
Dhani Ahmad
 
Risk management i
Risk management iRisk management i
Risk management i
Dhani Ahmad
 
Privacy & security in heath care it
Privacy & security in heath care itPrivacy & security in heath care it
Privacy & security in heath care it
Dhani Ahmad
 
Physical security
Physical securityPhysical security
Physical security
Dhani Ahmad
 
Legal, ethical & professional issues
Legal, ethical & professional issuesLegal, ethical & professional issues
Legal, ethical & professional issues
Dhani Ahmad
 

More from Dhani Ahmad (20)

Strategic planning
Strategic planningStrategic planning
Strategic planning
 
Strategic information system planning
Strategic information system planningStrategic information system planning
Strategic information system planning
 
Opportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysisOpportunities, threats, industry competition, and competitor analysis
Opportunities, threats, industry competition, and competitor analysis
 
Information system
Information systemInformation system
Information system
 
Information resource management
Information resource managementInformation resource management
Information resource management
 
Types of islamic institutions and records
Types of islamic institutions and recordsTypes of islamic institutions and records
Types of islamic institutions and records
 
Islamic information seeking behavior
Islamic information seeking behaviorIslamic information seeking behavior
Islamic information seeking behavior
 
Islamic information management
Islamic information managementIslamic information management
Islamic information management
 
Islamic information management sources in islam
Islamic information management sources in islamIslamic information management sources in islam
Islamic information management sources in islam
 
The need for security
The need for securityThe need for security
The need for security
 
The information security audit
The information security auditThe information security audit
The information security audit
 
Security technologies
Security technologiesSecurity technologies
Security technologies
 
Security policy
Security policySecurity policy
Security policy
 
Security and personnel
Security and personnelSecurity and personnel
Security and personnel
 
Secure
SecureSecure
Secure
 
Risk management ii
Risk management iiRisk management ii
Risk management ii
 
Risk management i
Risk management iRisk management i
Risk management i
 
Privacy & security in heath care it
Privacy & security in heath care itPrivacy & security in heath care it
Privacy & security in heath care it
 
Physical security
Physical securityPhysical security
Physical security
 
Legal, ethical & professional issues
Legal, ethical & professional issuesLegal, ethical & professional issues
Legal, ethical & professional issues
 

Recently uploaded

Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
g4dpvqap0
 
Nanandann Nilekani's ppt On India's .pdf
Nanandann Nilekani's ppt On India's .pdfNanandann Nilekani's ppt On India's .pdf
Nanandann Nilekani's ppt On India's .pdf
eddie19851
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
mbawufebxi
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Enterprise Wired
 

Recently uploaded (20)

Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
 
Nanandann Nilekani's ppt On India's .pdf
Nanandann Nilekani's ppt On India's .pdfNanandann Nilekani's ppt On India's .pdf
Nanandann Nilekani's ppt On India's .pdf
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
 

Chapter 05 looping

  • 1. Looping StatementLooping Statement Chapter 5 MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 2. IntroductionIntroduction Looping statements in PHP are used to execute the same block of code a specified number of times. ◦ While  loops through a block of code if and as long as a specified condition is true ◦ do...while  loops through a block of code once, and then repeats the loop as long as a special condition is true ◦ For  loops through a block of code a specified number of times ◦ Foreach  loops through a block of code for each element in an array MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 3. The while StatementThe while Statement The while statement will execute a block of code if and as long as a condition is true. while (condition) code to be executed; MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 5. The do...while StatementThe do...while Statement The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true. Syntax do { code to be executed; } while (condition); MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 6. ExampleExample  The following example will increment the value of i at least once, and it will continue incrementing the variable i as long as it has a value of less than 5: MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 7. The for StatementThe for Statement The for statement is used when you know how many times you want to execute a statement or a list of statements. Syntax for (initialization; condition; increment) { code to be executed; } MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 8. The for StatementThe for Statement The for statement has three parameters. The first parameter initializes variables The second parameter holds the condition The third parameter contains the increments required to implement the loop If more than one variable is included in the initialization or the increment parameter, they should be separated by commas. The condition must evaluate to true or false. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 9. ExampleExample What is the result of the following code? MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 10. The foreach StatementThe foreach Statement The foreach statement is used to loop through arrays. For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop, you'll be looking at the next element. MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 11. Syntax foreach (array as value) { code to be executed; } MOHAMAD RAHIMI MOHAMAD ROSMAN
  • 12. ExampleExample <html> <body> <?php $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: " . $value . "<br />"; } ?> </body> </html> MOHAMAD RAHIMI MOHAMAD ROSMAN What is the result of the following code?
  • 14. <?php $id=array("2001","2002","2003","2004"); $name=array("Rahul","Yunos","Mubin","Anuar"); $class=array("3A","3B","3C","3D"); $cgpa=array("3.56","3.49","3.85","3.63"); echo "Last week, a student named ".$name[0].", with UiTM ID ".$id[0].", from class ". $class[0]." with a CGPA of ".$cgpa[0]." has been choosen to represent our university for a debate tournament"; echo "<br>";echo "<br>"; echo "Last week, a student named ".$name[1].", with UiTM ID ".$id[1].", from class ". $class[1]." with a CGPA of ".$cgpa[1]." has been choosen to represent our university for a debate tournament"; echo "<br>";echo "<br>"; echo "Last week, a student named ".$name[2].", with UiTM ID ".$id[2].", from class ". $class[2]." with a CGPA of ".$cgpa[2]." has been choosen to represent our university for a debate tournament"; echo "<br>";echo "<br>"; echo "Last week, a student named ".$name[3].", with UiTM ID ".$id[3].", from class ". $class[3]." with a CGPA of ".$cgpa[3]." has been choosen to represent our university for a debate tournament"; ?> Changes the following codes by using the looping functions