+ 1

How can we use the break statement to end loops in c++?

30th Dec 2017, 9:05 PM
Dhar.m
Dhar.m - avatar
4 Answers
+ 4
Whenever you call "break;" inside of a loop stops it, if instead you call "continue;" it directly goes to the next iteration. What @James Jones meant was he creates an integer let's say "int stop = 0;" Then inside of the loop "while(!stop)" you just need to set stop to anything else than 0 to end the loop. However, unlike the break statement it will still execute the rest of the while content before stopping.
30th Dec 2017, 9:30 PM
Dapper Mink
Dapper Mink - avatar
+ 2
well typically what I do is make the loop a while loop so you can create an interger to end the loop
30th Dec 2017, 9:19 PM
James Jones
James Jones - avatar
+ 2
k. Thanks, James & QuentinJanuel
30th Dec 2017, 9:32 PM
Dhar.m
Dhar.m - avatar
+ 1
pls explain further.
30th Dec 2017, 9:24 PM
Dhar.m
Dhar.m - avatar