1
How do pro while identify that will exceed the count set in the form and pause before?
FORM:
<form method="get" action="exercico04.php">
Inicio: <input type="number" name="inicio" value="1" max="100" min="1"/><br/>
Final: <input type="number" name="final" value="1" max="100" min="1"/><br/>
Incremento:
<select name="incremento">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br>
<input type="submit" value="Contar" class="botao"/>
PHP:
$inis = isset($_GET["inicio"])?$_GET["inicio"]:0;
$finis = isset($_GET["final"])?$_GET["final"]:0;
$incris = isset($_GET["incremento"])?$_GET["incremento"]:0;
if($inis < $finis){
echo $inis . " ";
while($inis < $finis) {
$inis+=$incris;
echo $inis." ";
}
}else if($inis > $finis){
echo $inis . ",";
while($inis > $finis) {
$inis-=$incris;
echo $inis ." ";
}
}
In the case, for example, if I choose START 7, FINAL 45 and INCREMENT 4, it will count like this: 7 11 15 19 23 27 31 35 39 43 47
Only in this case, I want him to stop before he gets to 45, which would be case number 43. How do I do that?
End is less than start?
– Don't Panic
Everson. The whole PHP Code doesn’t want to appear there, but it would look like this: $Inis = isset($_GET["start"])? $_GET["start"]:0; $Finis = isset($_GET["final"])? $_GET["final"]:0; $incris = isset($_GET["increment"])? $_GET["increment"]:0; if($Inis < $Finis){ echo $Inis . " " ; while($Inis < $Finis) { $Inis+=$incris; echo $Inis." " ; } } Else if($Inis > $Finis){ echo $Inis . " ,"; while($Inis > $Finis) { $Inis-=$incris; echo $Inis ." " ; } }
– Lucas de Carvalho