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
8.0k 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.8k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories