How to do a while with 2 checks

Asked

Viewed 51 times

2

I’m trying to get while to take 2 values to stop but it just doesn’t enter while, I’m starting programming so try to help in a simple way

Objective of the code: To achieve the 0 of a function of 1 degree in a dynamic way...

<?php 

print("Qual é o expoente de sua função?\n");
$menu = fgets(STDIN);
if ($menu == 1) {
    print("Coloque o valor de A:");
    $a = fgets(STDIN);
    print("Coloque o valor de B:");
    $b = fgets(STDIN);
    $xa = 106000;
    $xb =-102000;
                while($mediaA=0.5 and $mediaB=-0.5){

                    $resultA = $a*$xa+$b;
                    $resultB = $a*$xb+$b;
                    $mediaA = $resultA/2;
                    $mediaB = $resultB/2;
                    $resultmedia = $a*$media+$b;
                    if($mediaA > 0 and $mediaB > 0){
                        $xb = $resultB;
                        $xa = $mediaB;
                    }elseif($resultB<0){
                            $xa = $mediaA;
                            $xb = $mediaB;
                    }elseif($mediaA < 0 and $mediaB < 0) {
                            $xb = $mediaB;
                            $xa = $resultA;
                            }elseif($mediaB>0) {
                            $xa = $mediaB;
                            $xb = $mediaA;
                            }               
                    }
            print($mediaA.$mediaB);                                 
    }
?>

1 answer

3

I take it you don’t want to do an assignment but a comparison, right? If it is it should contain "==" instead of "=", because if the assignment works it will always return true.

while($mediaA==0.5 and $mediaB==-0.5){

Browser other questions tagged

You are not signed in. Login or sign up in order to post.