MicroBasic If <condition> then
7 years 10 months ago #29530592
by Trainee
MicroBasic If <condition> then was created by Trainee
Hello,
I have a question about MicroBasic programming in Roborun. Is it possible to put an 'if' condition under an 'elseif' condition? For example :
if <condition> then
<block>
else if <condition> then
if <condition> then
<block>
else if <condition> then
<block>
end if
end if
I have a question about MicroBasic programming in Roborun. Is it possible to put an 'if' condition under an 'elseif' condition? For example :
if <condition> then
<block>
else if <condition> then
if <condition> then
<block>
else if <condition> then
<block>
end if
end if
Please Log in or Create an account to join the conversation.
7 years 10 months ago #29530593
by TechSupport
Replied by TechSupport on topic MicroBasic If <condition> then
Yes.
It would be "elseif" as one word and not 2 separate words. You'll know if it is correct as the color will change(black to blue) on the letters.
It would be "elseif" as one word and not 2 separate words. You'll know if it is correct as the color will change(black to blue) on the letters.
The following user(s) said Thank You: Trainee
Please Log in or Create an account to join the conversation.
7 years 10 months ago #29530594
by Trainee
Replied by Trainee on topic MicroBasic If <condition> then
Thank you very much.
I wrote a simple script to test but I couldn't build the code; the error says that 'unexpected end of file' at line 20, column 0. I don't know where is the problem. Could you check it out for me please?
a=10
b=5
c=5
top:
if a>b then
if c>10 then
print("d=1","\n")
elseif c>1 then
print("d=2","\n")
end if
else
if c>10 then
print("d=3")
elseif c>1 then
print("d=4")
end if
wait(1)
goto top
I wrote a simple script to test but I couldn't build the code; the error says that 'unexpected end of file' at line 20, column 0. I don't know where is the problem. Could you check it out for me please?
a=10
b=5
c=5
top:
if a>b then
if c>10 then
print("d=1","\n")
elseif c>1 then
print("d=2","\n")
end if
else
if c>10 then
print("d=3")
elseif c>1 then
print("d=4")
end if
wait(1)
goto top
Please Log in or Create an account to join the conversation.
7 years 10 months ago #29530595
by TechSupport
Replied by TechSupport on topic MicroBasic If <condition> then
You're missing some end if statements. For a set of if statements, you have to close out each with an end if. See example below. You may want to add in another argument for C>1 in the event it >10 as it will also trigger that set of actions since there aren't any restrictions.
If a>b then
action
elseif b>a then
action
else
no action
end if
if c=a then
action
else
different action
end if
If a>b then
action
elseif b>a then
action
else
no action
end if
if c=a then
action
else
different action
end if
Please Log in or Create an account to join the conversation.
Moderators: tonysantoni
Time to create page: 0.089 seconds