Search specification for instruction "forever"


#1

Hello
I asked my son to make a program displaying a color based on the distance measured by the ultrasonic sensor.
He realized a program, imperfect, and I can not explain the behavior:

he placed a “forever” instruction inside a touch detection test on the A key on the remote control.
so, normally, after pressing the A key its program falls into an infinite loop, and the led should react as requested green / red …
but in reality, he does not have enough time to press his button, so the led should be blue. (# 00ffbf)

But after downloading and starting the mbot, without pressing the remote control, the LEDs turn green or red depending on the distance ??
(which is normally expected after pressing the key)
So I looked at the code C, that I do not control very well, and in line 20 corresponding to the press on the key A, there is no instruction?

Can you help me understand?
thank you in advance


#2

You may try this program


#3

first of all thank you for answering me, and i can confirm that this program runs on the mbot.

However, my misunderstanding persists. why does forever instruction, placed inside an alternative, modify the evaluation of the condition of this alternative?

Prog 1: if I do not press the A key, I get the blue led
Prog 2: if I do not press the A key, I get the green led

That’s why I was looking for a specification for the forever statement.
Do you know if there is a reference manual for mblock?
Do you confirm that the behavior I observe is reproducible on your environment?

cordially

Prog1 :
image

Prog2 :
image


#4

Without forever loop, any block only runs one time. For the led light, the last color will lasts forever and middle color runs (one time) too fast to be caught by eyes.


#5

#6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.