Question

Control Structures - Loops and Conditional Statements in PHP, write an original code using one of...

Control Structures - Loops and Conditional Statements in PHP, write an original code using one of the control structure statements and submit it as your programming assignment.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

A control structure is a block of code that decides the execution path of a program depending on the value of the set condition.

Control Structure: for loop

Syntax:

for (init counter; test counter; increment counter)

{
    code to be executed for each iteration;
}

Program: control.php : Below is the program to display even number between 1 to 10.

<?php
//creating for loop
for($i=1; $i<10; $i++)
{
   if($i%2==0)//checking if value of i is even
       echo" $i"; //display value of i
}
?>

in above program for loop is used as control structure which initialize to $i = 0, we test condition for $i<10 and we increment value of $i by one. In for loop body conditional statement is used for checking value of $i, if value is even we display the value of $i.

Add a comment
Know the answer?
Add Answer to:
Control Structures - Loops and Conditional Statements in PHP, write an original code using one of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT