Can some explain this one? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can some explain this one?

These 2 codes are equivalent? 1. While(abc) System.out.print("hi"); 2. If(abc) System.out.print("hi"); Ignore syntax if any

6th Jul 2021, 6:01 PM
Phan Thanh Bình
Phan Thanh Bình - avatar
3 Answers
+ 1
Nope, the first will continue printing while <abc> can be evaluated as true. The second will decide whether or not to print deoending on whether <abc> was true.
6th Jul 2021, 6:14 PM
Ipang
+ 1
Ah, means if abc is true, the first will run infinity, the second just run once
6th Jul 2021, 6:21 PM
Phan Thanh Bình
Phan Thanh Bình - avatar
0
Yes, except something changes <abc> to false in while...loop body, it will run infinitely.
6th Jul 2021, 6:24 PM
Ipang