Limiting number of items in CoBlocks list?

Hi! I’m currently writing a piece of code, and I want to limit the number of items in a list. I have two variables, one is a boolean, and the other is my list. I made some code that would set the boolean variable to ‘false’ whenever the number of items in my list reaches 4. I know that lists start from 0, so I did change it to three.

I used the function ‘if length of “punched” (my list) = 3, set boolean to false’. However, it doesn’t work. Perhaps the length of punched means something else? In that case, what can I do to carry out my original plan?

Unfortunately, I couldn’t upload a screenshot - there were some technical issues.

Thanks so much!

Hi @Amie_LAU,

length returns the size of the list, so if the list contains 4 elements, it would return 4. The numeration of the list starts from position 0 and the elements would take list positions from 0 to 3.

You can share your CoSpaces with us so I can take a look. Here is a tutorial how to do it:

Screenshot 2020-03-24 at 8.11.52 AM.png

Hi @Amie_LAU,

You have student account. Please ask your teacher to enable sharing for you

Hi How can reply by email to post ? @Amie_LAU