Comparing java and python for loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Comparing java and python for loops

Is it possible to run a for loop for a specific number of elements in a sequence? for example say I want to run a for loop only for the first 3 elements in this list: words = ["hello", "world", "spam", "eggs"] I know it is rare to be needed but in java setting boundaries about the for loop or determine how the counting variable changes(eg i++ or i-- in java) sometimes is really helpful! Thank you!

19th Feb 2017, 1:48 PM
Maria204
Maria204 - avatar
1 Answer
0
in this case the len function is useful
19th Feb 2017, 2:50 PM
punna devender