Problem with FOR loop

I think what’s in for is the same as what I handwritten 1 to 6 in if statements
But there’s a different move. Where did it go wrong?
The code inside was written by copying and pasting
When I alternated between the two versions, only the ones written in if (from 1 to 6) worked properly

When I pressed gxUpButtonPress or gxDownButtonPress (i is the floor of the building), I wanted gxElevatorA.moving to be true
So I wrote it in a form, but it didn’t go as I wanted
bandicam 2024 02 27 17 36 02 141 (
bandicam 2024 02 27 17 38 19 223 복사본 (

Hi @limhyeonsoo I’m not patient enough to watch all your videos. I would need source code backup on my PC or online meeting for that. But what about to use debugger to step by step your code execution, I think this would help a lot in this case or what do you think? B&R Online Help

1 Like
When I watch debugging, when the ‘i’ is 1, it doesn’t work the way I want it to in upbuttonpress

→ first of all, your loop iterate from 0 to 5 but your array in watch is from 1 to 6
→ your array values for gxUpButtonPressed as well as for gxDownButtonPressed are FALSE, your condition in IF statement of these button is waiting for TRUE value, so behavior for buttons iteration from 1 to 5 is correct. Condition is not met, content of IF and ELSEIF statement is not executed.

This brings up additional note from me , check how you access arrays items in your code. If you have more lines like that then very likely you are overwriting memory. So behavior will be always weird :slight_smile: colleagues here have already provided you nice examples how to do it better (check your previous question).

I thought the syntax of ‘elsif’ wouldn’t work because I didn’t click on ‘upbuttonpress’ number 1
Thanks for the answer, I found it during a quick check while changing my last question
I’ll take a closer look at your answer

I thought I understood, but I was wrong and thought I understood.

1 Like

if you solved your problem, please mark this question as a solved :slight_smile: so we can focus on other questions :slight_smile: