Page 241 - Computer Software Application TP - Volume 1
P. 241
COMPUTER SOFTWARE APPLICATION - CITS
EXERCISE 51 : Demonstrate on if statement Using the
else clause with if statement, switch
statement Using the? operator, while
statement, do while statement, for
statement, Breaking out of loops, Nesting
loops
Objectives
At the end of this exercise you shall be able to
• use if-else and while statement in PHP
• use while and for loops in PHP
• use ? operator and nesting loops in PHP.
Requirements
Tools/Materials
• Computer/Laptop with latest configuration • PHP
• Operating system: windows 10 or 11 • Text editor
• Apache web server • Web browser
Procedure
TASK 1: Using If statement
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
$age = 21;
if ($age>18)
{
echo “You are eligible for DL”;
}
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
226