+ 1

What is the largest number that will be printed by this code? Explain(Detail by Detail) plz.

for (int x = 1; x < 8; x++) { if (x > 5) break; Console.WriteLine(x); } //Oh and what does the break; do in this code exactly

28th Jan 2017, 5:41 AM
Christopher
3 Answers
+ 5
5 cause that will print 1, 2, 3, 4, 5 then x wil be 6 and 6 > 5 so the break will get execute and that will tell the program to stop executing that loop so it wont print the last value of x that is 6 cause the break will stop the loop
28th Jan 2017, 5:43 AM
Kawaii
Kawaii - avatar
+ 1
Thank You a lot :)
20th Jun 2017, 5:45 AM
Șute
Șute  - avatar
0
This is wrong explanation. As "if" wont execute until condition satisfied. But it will still print the no.s. So the output will be like this: 1 2 3 4 5 Highest:5 #loops #break
10th Oct 2022, 5:01 PM
Simanjali Jena
Simanjali Jena - avatar