January 2015
Beginner to intermediate
85 pages
1h 58m
English
VimL has a while loop. It starts with while and a condition, and it ends with endwhile:
| intro/loop.vim | |
| | let animalKingdom = ['Crocodile', 'Bug', 'Octopus', 'Penguin'] |
| | |
| | while len(animalKingdom) > 0 |
| | echo animalKingdom[0] . ' Friend' |
| | call remove(animalKingdom, 0) |
| | endwhile |
| | |
| | " → Crocodile Friend |
| | " Bug Friend |
| | " Octopus Friend |
| | " Penguin Friend |
The condition here, len(animalKingdom) > 0, checks that the size of animalKingdom is greater than 0. To do that, it uses len. On a List, this function returns the number of items. It can also be used to get the length of a String value, but there’s a dedicated function, strlen, for that.
In the body of the while loop, the first statement, echo ...
Read now
Unlock full access