1. Create a file named: Loops2.php in your text editor. 2. Create a FOR loop tha
ID: 3550571 • Letter: 1
Question
1.Create a file named: Loops2.php in your text editor.
2.Create a FOR loop that displays numbers 111-144, but skips 130 using a CONTINUE within an if statement. All numbers should be on one line. Use any separator you wish, but at least a space for readability.
3.Create a FOR loop that displays numbers 111-144, but stops after 124 using a BREAKwithin an if statement. All numbers should be on one line. Use any separator you wish, but at least a space for readability.
4.Create a FOR loop within a FOR loop scenario (per the Break Video) that displays two variables, each with ranges 0 - 7. Use a CONTINUE in the first loop using the modulo approach (e.g., if ($c1 % 2 == 0) {continue;}) and use a BREAK in the second loop when the second variable ==6. The BREAK should affect BOTH loops! Again, all numbers should be on one line. Use any separator you wish, but at least a space for readability.
5.Copy this last double loop code and Paste below it. NOW have the BREAK only affect the SECOND loop! Your output result should be quite differemt!
6.Create an array with the following values: 205, 306, 407, 508, 609. Echo the first three items by pointing to the current item, then reset the pointer and echo the first current item. All numbers should be on one line. Use any separator you wish, but at least a space for readability.
7.Create a WHILE loop that displays each array item on one line with a pound-sign (#) separator.
8.EXTRA CREDIT (5 points): Remove the final # separator within the loop. Output should look like the sample. (Hint: needs a simple if statement)
9.Here is a sample of what your output should look like.
Continue:
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 131 132 133 134 135 136 137 138 139 140 141 142 143 144
Break:
111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124
Double Loops:
1-0 / 1-1 / 1-2 / 1-3 / 1-4 / 1-5 /
1-0 / 1-1 / 1-2 / 1-3 / 1-4 / 1-5 / 3-0 / 3-1 / 3-2 / 3-3 / 3-4 / 3-5 / 5-0 / 5-1 / 5-2 / 5-3 / 5-4 / 5-5 / 7-0 / 7-1 / 7-2 / 7-3 / 7-4 / 7-5 /
Array Pointers:
1: 205 / 2: 306 / 3: 407 / 4: 205
205 # 306 # 407 # 508 # 609
Explanation / Answer
I have lot off efforts for your problem. just save it and run it.
<?php
//First Assignment
echo "Continue<br/>";
for($i=111;$i<=144;$i++)
{
if($i==130)
{
continue;
}
echo " ".$i;
}
//Second Assignment
echo "<br/>Break<br/>";
for($k=111;$k<=144;$k++)
{
if($k==125)
{
break;
}
echo " ".$k;
}
//Third Assignment
echo "<br/>Double Loops<br/>";
for($c1=1;$c1<=7;$c1++)
{
if($c1%2==0)
{
continue;
}
for($n=1;$n<=7;$n++)
{
if($n==6)
{
break;
}
echo " ".$c1."-".$n;
}
echo "<br/>";
}
//Fourth Assignment
echo "<br/>Array Pointers<br/>";
$count=1;
$a=array(205,306,407,508,609);
foreach($a as $key=>$value)
{
if($key==3)
{
echo $count.": ".$a[0];
break;
}
echo $count.": ".$value."/ ";
$count++;
}
//Fifth Assignment
echo "<br/>Using While Loop to show item with pound-sign(#):<br/>";
$i=count($a);
while($i!=0)
{
echo " #".$a[$i-1];;
$i--;
}
//Sixth Assignment
echo "<br/>No need to remove final(#)
i have already done it in Fith Assignment";
?>
Output:
Continue
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 131 132 133 134 135 136 137 138 139 140 141 142 143 144
Break
111 112 113 114 115 116 117 118 119 120 121 122 123 124
Double Loops
1-1 1-2 1-3 1-4 1-5
3-1 3-2 3-3 3-4 3-5
5-1 5-2 5-3 5-4 5-5
7-1 7-2 7-3 7-4 7-5
Array Pointers
1: 205/ 2: 306/ 3: 407/ 4: 205
Using While Loop to show item with pound-sign(#):
#609 #508 #407 #306 #205
No need to remove final(#) i have already done it in Fith Assignment
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.