# How to break out of nested for loops?.

Page 1 of 1

## 1 Replies - 202 Views - Last Post: 30 April 2019 - 07:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=415948&amp;s=e4af0c0a95c4658c68c8675af65d5b0d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 albert003

Reputation: 30
• Posts: 719
• Joined: 15-December 14

# How to break out of nested for loops?.

Posted 30 April 2019 - 07:27 PM

So, I'm stuck on chapter 3. The author wants me to TRY THIS .. Implement square() without using the multiplication operator; that is, do the x*x by repeated addition (start a variable result at 0 and add x to it x times). Then run some version of "the first program" using that square().

I thought instead of trying to over complicate everything I thought I would use simple math to find the square root without using the sqrt() function.I found an article to prove my idea would work. So what I did was use two nested loops and have them multiply till they came with the answer equal to what was inputted by the user, then use some more math to find the answer. I realise I still have a lot to do, but right now I'm trying to get this part of the program working before I work on the rest of the math required to make it work.

This is the article I'm fine tuning my idea.

So my question is I'm ,currently stuck on trying to find a way to break the nested loops once I find the two integers that equal the number inputted. I've tried everything I could think of and nothing works.

Could I please get a hint or a suggestion?

This is the program

```#include <iostream>
#include <math.h>
int main()
{
double input;
double ans;
std::cout << "Enter number" <<std::endl;
std::cin >> input;
for(int x = 0; x < 11; x++)
{
for(double z = 0.0; z < 11; z++)
{
ans = x * z;
std::cout << x <<" * "<< z <<" = "<<ans <<std::endl;
if(ans = x * z)
break;
}
if()
break;
}
}

```

Is This A Good Question/Topic? 0

## Replies To: How to break out of nested for loops?.

### #2 albert003

Reputation: 30
• Posts: 719
• Joined: 15-December 14

## Re: How to break out of nested for loops?.

Posted 30 April 2019 - 07:44 PM

Disregard my initial post. I just realized reading the instructions the author again that I was doing the whole program incorrectly.