Tags | technical-assessment skill/for_loops |
Many people do pattern matching instead of understanding. Here are some common things that will be tested:
On Tilde you’ll notice that this card is asking for a link submission. Please don’t worry about submitting a link. You will be assessed according to TOPIC: Introduction to live assessments
for (some_initialiser,some_check,some_update){
...
}
They should be able to reason about each of the different parts of the configuration of the loops.
range
and in
for x in [1,2,3,4,5]:
...
for x in range(len(arr))
...
enumerate
.for i in range(5):
print('a')
print('b')
arr = ['a','b','c']
for (let i = 0; i< arr.length; i++){
console.log(i) // this does not print a, b or c ever
}
for n in [0,1,2]:
for m in [0,1,2]:
print(n,m) # this executes 9 times. Why? What gets printed?
print("here") # this one only executes 3 times. Why?
E.g.:
for (let i = 0; i < 5; i++){
print(i)
print("a")
if (i <2) continue; // what does this do?
print("b")
if (i>4) break; // how about this?
print("c")
}
continue
and break
within a nested for loopfor (let n=0; n<3; n++){
print(n)
for (let i = 0; i < 5; i++){
print(i)
print("a")
if (i <2) continue; // what does this do?
print("b")
if (i>4) break; // how about this?
print("c")
}
}
Some people think you need to turn strings into arrays before you can start iterating over them. This is not the case!
break
and continue
statements work in while loops versus for loops?