Meta commands
-
@alankilian, I will test that but the semicolon is there to comment out the line and should not cause this reaction.
-
@jens55 This works to keep the whitespace:
while iterations < 10 m118 s{"hello world " ^ iterations} ; m118 s{"hello world " ^ iterations} g4 s2 continue
-
@alankilian
@dc42
Ahhhh, I need the spaces before the comment .... ok but that s a bug in the interpreter -
This post is deleted! -
@jens55 said in Meta commands:
Ahhhh, I need the spaces before the comment .... ok but that s a bug in the interpreter
From the documentation:
The body ends just before the first line that is not indented.
So, it could be argued that the interpreter is working fine.
It's not up to me to decide.
I'm happy you're getting going on your project again.
And I learned some things from this discussion, so thank you for that also.
-
@dc42
Here is another example of strange behaviour:while true if iterations < 10 m118 s"hello world" g4 s2 continue break
This executes but leaves the printer in a 'busy' state
Without the 'break' command it does the same
If I move the 'break' command to the right by two spaces, everything finishes ok - it breaks out of the loop
Point is, there is no such thing as an 'endif' to clearly identify where the 'if' statement ends. IMHO there should be (optional maybe) an 'endif' for readability but in any case, the 'break' should break out of the loop no matter what.Edit: On re-reading this, there is a flaw in my thinking here, and unless the 'break' is indented two spaces over, the 'while' loop has no exit. Interesting note here is that the iteration variable apparently isn't reset until after exiting the 'while' loop because it only prints 'hello world' for one 'if' loop.
That to me seems rather odd .... -
@jens55
Nothing strange about it.
Using "while true" creates an infinite loop
This is a dangerous practice for the uninitiated as you must ensure that at some point you have a conditional that triggers a break command.
You have not done so. Therefore the loop continues.
Once it gets to iteration 10 it just stops sending the echo.You should have put
'if iterations < 10 Echo "blah blah" else break
Your continue command is useless as it's not part of the while construct.
The point of continue is to skip an iteration.'if iterations < 10 if iterations = 5 continue Echo "blah blah" ; won't happen on #5 else break ; required to end loop
It's safer to use
while iterations < 10
blah blahEDIT
Sorry. Doing this on my phone so I could not see your code
Your BREK is outside the whole loop, but the comments stand -
Here is another thing that strikes me as odd:
while true if iterations < 10 m118 s"hello world" g4 s2 continue if iterations < 11 m118 s"hello north america" g4 s2 continue break
This code will execute the first 'if' for 10 times but will not reset 'iterations' as I would have expected and because of that will only execute the second 'if' loop once.
-
@owend said in Meta commands:
Your continue command is useless as it's not part of the while construct.
The point of continue is to skip an iteration.To skip an iteration ???? Where did you see this in the documentation ???
I look at 'continue' as a command that strictly exists as a means to improve readability of the code since the command itself seems to do diddly squat and can be left out. -
@jens55 said in Meta commands:
@owend said in Meta commands:
Your continue command is useless as it's not part of the while construct.
The point of continue is to skip an iteration.To skip an iteration ???? Where did you see this in the documentation ???
'continue' jumps back to the BEGINNING of a loop.
So if you have the following story: (COMPLETELY useless, but trying to illuminate how 'continue' is used)
while iterations < 10 m118 s{"This is iteration " ^ iterations} if iterations > 5 continue ; Don't do this stuff after the first 5 iterations m118 s{"Perform this action on " ^ iterations}
This is iteration 0 Perform this action on 0 This is iteration 1 Perform this action on 1 This is iteration 2 Perform this action on 2 This is iteration 3 Perform this action on 3 This is iteration 4 Perform this action on 4 This is iteration 5 Perform this action on 5 This is iteration 6 This is iteration 7 This is iteration 8 This is iteration 9
-
@jens55 said in Meta commands:
Here is another thing that strikes me as odd:
while true if iterations < 10 m118 s"hello world" g4 s2 continue if iterations < 11 m118 s"hello north america" g4 s2 continue break
This code will execute the first 'if' for 10 times but will not reset 'iterations' as I would have expected and because of that will only execute the second 'if' loop once.
Why do you think 'iterations' will get reset to zero?
'iterations' counts the number of times through the loop.Your 'if' statements will not affect the iteration count at all.
-
@jens55 said in Meta commands:
To skip an iteration ???? Where did you see this in the documentation ???
I look at 'continue' as a command that strictly exists as a means to improve readability of the code since the command itself seems to do diddly squat and can be left out.To be clear it doesn't skip an iteration, it skips everything after the continue statement in the current iteration. It goes back to the top of the looping structure and starts the next iteration. Every programming language I can think of works this way.
-
@jens55 I'm trying to help you understand how this works, but your responses seem to be accusatory (the interpreter is broken) and inflammatory, so if you don't change your attitude, I'll check out of this conversation.
I'm really trying to help you understand how to write programs in a clear understandable way.
Ref: I'm a retired embedded-systems software and hardware engineer who has been programming since about 1978, so I've got the experience to be able to help and in addition, you can help me learn new things also if we both work together on it.
-
@alankilian, I REALLY appreciate any and all help and I apologize if you felt in any way slighted whatsoever. It was most certainly not my intent !!!
I got confused by the sentence "The point of continue is to skip an iteration."
DanS79 cleared it up and confirmed my interpretation by saying "To be clear it doesn't skip an iteration, it skips everything after the continue statement in the current iteration." IE it doesn't skip an iteration but goes back to the beginning of the loop.
Your example (thanks) did however clarify another point on the continue command that I was not aware of and hence my earlier confusion about sequential 'if' statements. The iteration happens over the 'while' loop and not as I had assumed over the 'if' loop. A very important bit of learning for me!
So to repeat, I apologize profusely and hope we are back on the same wavelength ! -
@jens55 Awesome!
AND, you got me to try some new stuff using meta-commands, so everyone wins.
-
@jens55
Poor choice of words on my part. , but the code should have been clear enough
Apologies for confusing you.
I'm Australian, so English isn't my first language -
@owend, no problem and thanks for chiming in !