You are on page 1of 5

LN.

3 DECISION MAKING IN PHP

CW
INT /Ron/ PAGE NO. I. Technical Terms:
T.B
CW 1. Execute
CW 2. Evaluates
CW 3. Default
CW 4. Initialisation
CW 5. Increment
CW 6. Decrement

II. Fill in the blanks:


INT T.B.M Pg No:31 1. File Sharing is the sharing of a computer's data on a network.
INT T.B.M Pg No:21 2. The control statements are used to take decision based on different scenarios.
INT T.B.M Pg No:26 3. The looping statements of PHP are While loop, Do-while loop and For loop.

Pg No:33 III. Choose the correct answer:


TB 1. The statement that executes as a set of blocks is
a. if-else b. do-while c. switch-case d. else-if
TB Pg No:33 2. The syntax for do-while loop is,
a. do b. do c. do d. do while
{ statement } statement (statement) (condition)
while(condition); (while) while { statement
condition: { }:
condition:}

TB Pg No:33 3. The loop used to execute a set of statements specified number of times is
a. if-else b. while c. do-while d. for
TB Pg No:33 4. The statement to terminate the execution of looping structures is,
a. stop b. break c. terminate d. exit
IV. Compare and Contrast:
Pg No:22
INT T.B.M Pg No:23 1. Compare and contrast if-else and switch statements.

If-else Switch case


* Executes one set of code when one of the condition * Evaluates the given expression and then seeks a matching
is true and executes another set of code if condition is ‘case value’. If it is found, then associated code will be
false. executed.

* Condition of if-else should always * Switch case can be written in any way that it compares a given
result either in true or false value with set of predefined values.

Pg No:28
INT T.B.M Pg No:29 2. Compare and contrast break and continue statements.

Break statement Continue statement


* The break statement terminates the current * In a loop iteration,if a particular statement
execution of current structures like has to be skipped,continue statement is used
for,foreach,while,do-while and switch.
* Whenever the control encounters break statement,it *Whenever the control encounters continue statement,it will not
terminates the execution and come out of the loop. terminate the execution.It is used to skip the current iteration of
the loop.

T.B P.No.30 V. Think and Write:


Write a program to print the sum of the first 10 numbers
<?php
$x=0;
$z=0;
do
{ $x=$x+1;
$z=$z+$x;
}while($x<10);
print $z;
?>
VI. Answer the following:

T.B Pg No:33 1. Short note on conditional statements.


The control statements are used to take decisions based on different scenarios.The control statements supported in PHP
are,
· If-else
· Elseif
· Switch
If-else statement : This statement is used to execute one set of code when one of the condition is true and the other is
false.
Elseif Statement : The elseif statement is used when one of the given conditions is true.

The switch statement: This switch statement is another type of control statement which will execute one of the many
blocks, based on the given Condition.

T.B Pg No:33 2. Write a program to print odd numbers from 1 to 20.


<?php
For($i=1;$i<20;$i+2)
{
Print "$i<br>";
}
?>

T.B Pg No:33 3. Write a program to print odd numbers from 21 to 30.


<?php
For($i=21;$i<=30;$i++)
{
Print "$i<br>";
}
?>
T.B Pg No:33 4. Write the differences between while and do-while statements.
While statement: Statements will be executed until the test
expression evaluates to false.
Do-while statement: Executes the statement first and then tests the condition.
If the conditions is true, the following iterations are executed. If false , loop
is terminated.

T.B Pg No:33 5. Write a program using for-each to print numbers from 10 to 20


<?php
$number=array(11,12,13,14,1,16,17,18,19,20);
Foreach ($number as $value)
{ Echo “$value<br>”; }
?>

VII. Write the syntax for the following:


INT T.B.M Pg No:22 1. if-else statement:

If(condition)
Statement executed if condition is true;
Else
Statement executed if condition is false;

INT T.B.M Pg No:22 2. ElseIf statement:

If(condition)
Statement executed if condition is true;
Elseif(condition)
Statement executed if condition is true;
else
Statement executed if condition is true;
3. Switch statement:
INT T.B.M Pg No:22
Switch(expression)
{
case value1:
statement1;
break;
case value2:
statement1;
break;
default:
statement;

}
INT T.B.M Pg No:26 4. While loop:
while(condition is true)
{
Statement(s) to be executed;
}

INT T.B.M Pg No:27 5. Do-while loop:


Do
{
Statement(s) to be executed;
}while(condition);

INT T.B.M Pg No:27 6. For loop:


For(initialisation;condition;increment/decrement)
{
Statement(s) to be executed;
}

You might also like