+ 1
While loop that accept int and string to stop the program .?
How can i write a code that when i input 2 numbers it will add or subtract or something and continue to ask 2 numbers until im not putting stop , stop . ? ex. 2 , 2 = 4 if i write stop stop the program will stop
2 Answers
+ 1
Thats where do while loop comes into play. So basically when you use a do while loop you want to run the execution at least once and then run again depending upon the condition. If the condition evaluates to true it is repeated again.
So syntax of do-while loop:
do
{
-------(lines of code)
}while( condition )
in the condition part, you can ask for user input and then according run your do while loop
for more information i recommend you to google it
0
string s= stop;
string input;
if (input.compareTo(s))
{
break;
}
// it will simply stop the loop.