14.7k views
5 votes
How many times does the computer print the string "Hello"? i = 2 while (i < 4) { print ("Hello") i = i + 1}:

User Alaster
by
7.9k points

1 Answer

7 votes

i=2<4 is true, so "Hello" is printed, then we increment
i by 1.

Now
i=3 and
3<4, so "Hello" gets printed again.

Next
i=4, but
4<4 is false, so the while loop is broken.

So, the loop only prints "Hello" twice.
User Hannes
by
7.7k points