-1
I have a vector with 16 elements. I want to show the elements of this vector using the repetition loop for
.
Output must be equal to this:
A
1
2
3
4
B
A
5
6
7
8
B
A
9
10
11
12
B
A
13
14
15
16
B
As the tie ended, there is no need to show the "To" just below the last B.
One remark: I only gave the value 16 as an example, but it can be any value, for example: 4, 5, 17, 25, 30, 100, etc.
I tried this code:
for($k = 0, $i = 0; $k <= 16 ; $k++, $i++){
if($k % 4)==0){
echo "A";
}
//Mostrar os números aqui
if($k % 5)==0){
echo "B";
}
}
https://repl.it/@TaffarelXavier/ForDemo
but without any success.
Wouldn’t just change the
$k <= 16
for$k <= 15
?!– Inkeliz
No, since 16 is just a number as an example, but it could be any number, as I showed in the question. Could be 4, 5, 17, 26, 40, 100,1000, etc.
– Taffarel Xavier
Why did you define
$i
in the loop if you didn’t even use it? If you need to also display the number, why not putecho $k
? Why do you start showing offA
and does not displayB
, since0 % 5
will be 0?– Woss
I fixed it, minus the $i, but I’m actually not getting the logic. I’d really like to show the output of the mentioned form.
– Taffarel Xavier
The problem is that it is not clear what is the logic to define the "mentioned form".
– Woss
I did. But thank you so much for trying.
– Taffarel Xavier