Semester
Subject
Year
Tribhuwan University
2080
Bachelor Level / Third Year / Fifth Semester / Science
(Web Technology II)
Full Marks: 60
Pass Marks: 24
Time: 3 Hours
Candidates are required to give their answers in their own words as for as practicable.
The figures in the margin indicate full marks.
Long Answers Questions
PHP code is embedded within HTML pages using special PHP tags that tell the web server to interpret the enclosed code as PHP.
There are four ways to embed PHP code in web pages:
a) Standard Tags (Recommended):
<?php
echo "Hello World";
?>
b) Short Open Tags:
<?
echo "Hello World";
?>
short_open_tag = On in php.inic) ASP-Style Tags:
<%
echo "Hello World";
%>
asp_tags = On in php.inid) Script Tags:
<script language="php">
echo "Hello World";
</script>
Key Points:
<?php ?> is the most portable and universally supported method
breakterminates the entire loop immediately, whilecontinueskips the current iteration and moves to the next iteration.
Program:
<?php
echo "<h2>Demonstration of Break Statement</h2>";
echo "Printing numbers 1 to 10, but breaking at 5:<br>";
for ($i = 1; $i <= 10; $i++) {
if ($i == 5) {
break; // Loop terminates completely when i equals 5
}
echo $i . " ";
}
echo "<br>Loop ended due to break.";
echo "<h2>Demonstration of Continue Statement</h2>";
echo "Printing numbers 1 to 10, but skipping 5:<br>";
for ($i = 1; $i <= 10; $i++) {
if ($i == 5) {
continue; // Skips iteration when i equals 5
}
echo $i . " ";
}
echo "<br>Loop completed, only 5 was skipped.";
?>
Output:
Demonstration of Break Statement
Printing numbers 1 to 10, but breaking at 5:
1 2 3 4
Loop ended due to break.
Demonstration of Continue Statement
Printing numbers 1 to 10, but skipping 5:
1 2 3 4 6 7 8 9 10
Loop completed, only 5 was skipped.
| Feature | break | continue |
|---|---|---|
| Action | Exits the entire loop | Skips current iteration only |
| Execution after | Code after loop executes | Next iteration begins |
| Use case | Stop searching after match found | Skip unwanted values |
Conclusion: PHP is embedded in HTML using <?php ?> tags. The break statement completely terminates loop execution, while continue only skips the current iteration and proceeds with the next one. Both are essential for controlling loop flow in PHP programs.
Short Answers Questions