WBDV Midterms

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

WEBDEV MIDTERMS LOOPS

- Loops execute a block of code a specified


CONTROL STRUCTURES number of times, or while a specified
- Conditional programmers to output different condition is true.
code based on specific conditions.
Types of loops:
Types of conditionals: 1. While
1. If statement 2. Do…while
2. If… else statement 3. For…
3. If… else if…else statement
4. Switch statement While loop
- Executes a block of code while a condition
is true.
If statement
- To execute some code only if a specified Syntax:
condition is true.
Syntax: While (condition)
If (condition) {
- Code to be executed if condition is true; Code to be executed:
}
Sample Code:
If ($x == 1) Sample Code:
Echo “True”; $x = 1;
While ($x < 5)
If…else statement {
- To execute some coder if a condition is true $x - $x = 1;
and another code if the condition is false. }
Syntax: echo $x
If (condition)
- Code to be executed if condition is true; For loops
else - Used when you know in advance how many
- Code to be executed if condition is false. times the script should run.

If…else if…else statement Syntax:


- To select one of several blocks of code to For [init; condition; increment]
be executed {
Syntax: code to be executed;
if(condittion) }
- Code to be executed if condition is true;
else(condition) Sample code:
- Code to be executed if condition is true;
else for($x x 1; $x < 5) $x ++)
- Code to be executed if condition is false; {
Echo $x. “<br/>”
Switch statement }
- To select one of several blocks of code to
be executed.
Syntax:

Switch(n)
{

case label1:
Code to be executed if n=label1;
break;
case label 2:
Code to be executed if n=label2;
break;
Default:
Code to be executed if n is different
from boh label1 and label2:
}
Code to be executed if condition is false;

You might also like