First define length-component error (personal term) :
This is an error when we want to get n-th component of a list if n is bigger then the length of the list. For example, Range[5][[7]]
yields {1, 2, 3, 4, 5}[[7]]
but with an error message.
Is there an option (I mean SetOptions
) to quit the loop, if length-component error occurs?
(Or any kind of error that yields an error message)
You can understand my question easily with screenshots. There are three codes.
Note that MyList = {1, 2, 3, 4, 5};
for all 3 codes.
If you think the best is Code 2, I would appreciate it if you wrote so.
Code 1 :
Code 2 :
Code 3 :