#StoneProfitsSystem


PHP - Decision Making Statements and Loops

If Else Statement:
  • If you want to execute some code if a condition is true and another code if a condition is false, use the if....else statement.


Switch Statement:
  • If you want to select one of many blocks of code to be executed, use the Switch statement.
  • The switch statement is used to avoid long blocks of if..elseif..else code.



For Loop Statement:
  • The for statement is used when you know how many times you want to execute a statement or a block of statements.

Syntax:

for (initialization; condition; increment){
code to be executed;
}

Example:



While Loop Statement:
  • The while statement will execute a block of code if and as long as a test expression is true.

Syntax:

while (condition) {
code to be executed;
}

Example:



Do While Loop 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);

Example:


No comments:

Post a Comment