0
How to avoid 'goto'
Why goto should be avoided and how to make my code without it?
3 Antworten
+ 3
use a while loop instead.
while(i < 10)
{
cout << "enter number greater than 10"<<endl;
cin >> i;
}
no need to use goto at all
+ 1
goto makes it hard to reason about code that uses it. You shouldn't need it to accomplish anything. If you have code using goto, post it and we'll come up with an equivalent version without it.
0
ok can someone make this without goto
#include <iostream>
using namespace std;
int main()
{
int i = 0;
again:
cout <<"Enter number greater than 10"<<endl;
cin >> i;
if (i < 10) {
goto again;
}
cout << i;
return 0;
}