0
Please what is the explanation of this code, it's a JavaScript program
<script> var result = 1; var counter =0; while (counter<10){ result=result *2; counter =counter +1; } document.write(result) ; </script>
3 odpowiedzi
+ 4
a while loop is running until the condition is false (if counter = 10 -> 10 < 10 -> false).
counter is 0 -> 0 < 10
result = 1 * 2 = 2
counter = 0 + 1 = 1
counter = 1 -> 1 < 10
result = 2 *2 = 4
counter = 1 + 1 = 2
-> 2 < 10
result = 8
counter = 3
-> 3 < 10
result = 16
counter = 4
-> 4 < 10
result = 32
counter = 5
-> 5 < 10
result = 64
counter = 6
-> 6 < 10
result = 128
counter = 7
-> 7 < 10
result = 256
counter = 8
-> 8 < 10
result = 512
counter = 9
-> 9 < 10
result = 1024
counter = 10
-> 10 < 10 is not true -> end loop
print result -> output: 1024
+ 3
Williams It is just an arrow sign which I use as a pointer/marker. I also use it to represent a chain.
0
Please what is the meaning of - >