how can i end this loop

masters how can i end this loop. pls




#include <iostream>
using namespace std;
int main()
{
int a=20, b=40, c=60;
bool d= true;
while (a<b)
cout << d;
}
Inside the loop, make a larger than b.
ok
like this or how pls
#include <iostream>
using namespace std;
int main()
{
int a=20, b=40, c=60;
bool d= true;
while (a<b)
cout << d;
while (a>b)
break;
}
That's still going to repeat forever.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main()
{
    int a=20, b=40, c=60;
    bool d= true;

    while (a<b)
        cout << d;

    while (a>b)
        break;
}


Here's a program that won't repeat:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main()
{
    int a=20, b=40, c=60;
    bool d = true;
    while (a < b)
    {
        cout << d;
        a = b; // a is no longer less than b
    }
    
    cout << "out of the loop" << endl;
}


In case it's not clear, the question your asking makes no sense because you're providing no context for what you're trying to do. A loop that always only runs once shouldn't be a loop in the first place. Rather, it should be an if statement.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
	int a = 20, b = 40, c = 60;
	bool d = true;
	while (a < b) {
		cout << d;
		a++;
	}
	cin.get();
}
tanks guys it work
hey guys
how did u posted dos code. your codes are color.
i mean i can run ur codes.but how did u do it pls ?
When you make a reply, you can see the main text box where you can type. Look just to the right... It says format: and under are a bunch of buttons to choose from. The very first button is for code. It looks like this "<>".
#include <iostream>
using namespace std;
int main()
{
cout <<"thank you all"<< endl;
return 0;
}
Last edited on
Topic archived. No new replies allowed.