循环计数时

时间:2018-11-24 18:14:25

标签: java while-loop

在Java中,我如何告诉while循环只要输入设备发送回较低的值就可以运行

<input type="checkbox" id="redirect30sid" name="redirect30sname" value="Redirectvalue">Redirect me after 30s

<script>
  const checkboxElement = document.getElementById('redirect30sid')
  checkboxElement.addEventListener('change', (event) => {
    if (event.target.checked) {
      setTimeout(function () {
        // Double check if the check box is still checked
        if (event.target.checked)
            window.location = checkboxElement.value;
      }, 30 * 1000);
    }
  })
</script>

1 个答案:

答案 0 :(得分:0)

您可以将最后一个值保存在变量中,然后将其与实际值进行比较。

 boolean continueBool= true;
 double lastValue=0;
 double leftDist = distanceSensorLeft.getDistance(DistanceUnit.MM);
 double rightDist = distanceSensorRight.getDistance(DistanceUnit.MM);
 leftDrive.setTargetPosition(leftDrive.getCurrentPosition() - 1500);
 rightDrive.setTargetPosition(rightDrive.getCurrentPosition() + 1500);
 leftDrive.setPower(0.2);
 rightDrive.setPower(-0.2);

 while (continueBool) {
        if(lastValue<=actualValue){
        continueBool=false;
    }

        lastValue=actualValue;

}