While I press the keypad I want the LCD to print the number and I want it to loop four times to show me the entered code while I type it. I can get it to work properly while using IF statement but since I will be doing a lot of similar coding throughout the project I want to avoid a lot of code by using FOR statement instead. I have tried a lot of different codes but cannot get it to do what I want. Could someone please help me out and tell me what I am doing wrong?
septillion:
You do know it will run 4 times no matter if it reads NO_KEY and SettingCode isn't equal to i?
And what on earth is that goto doing there?
For a better answer, post all your code.
You are right, off course it will. The problem is that I am still new to this kind of programming. I have a lot of experience in ABB industrial robots so I am used to it reading and executing every single line before it jumps to the next. The GOTO was a desperate attempt to get the program to wait until the key is no longer pressed, but I realize that won't work. What I am missing is a statement to use to get it to wait for me to release the key within the FOR loop. Maybe that is impossible and I need to go for IF statements after all.
A while loop would be better than using goto. You should avoid the use of goto unless you're absolutely sure there's no better option. Even then you should spend some more time thinking about it and you'll probably come up with an alternative.
pert:
A while loop would be better than using goto. You should avoid the use of goto unless you're absolutely sure there's no better option. Even then you should spend some more time thinking about it and you'll probably come up with an alternative.
I know. I tried that first but it didn't work. I guess I will have to go for the IF statement after all. I am used to rapid and PLC ladder programming so when I program a PLC with structured text I get too confused.
The main difference compared to ladder programming is that you want the loop() to just loop. Just remember how many times you did something and just skip over it as long as it's not time to do it again. That's called non-blocking and will allow you do do more then a single thing like slow human interaction.