# exiting loop

• ### Question

• User-2060576634 posted

hi folks . I've written this simple code to somehow convert decimals to fractions but I don't know how to exit the loop on first iteration to keep only one result. any ideas?

```    var share = (float)12 / 13;

for (var i = 1; i < 100; i++)
{
for (var n = 1; n < 100; n++)
{
var fraction= (float)i/n;
if (fraction == share)
{
<p>@i/@n</p>
}
}
}

```

Monday, November 16, 2015 4:36 PM

• User325035487 posted
```    var share = (float)12 / 13;
bool success = false;
for (var i = 1; i < 100; i++)
{
if (!success)
{
for (var n = 1; n < 100; n++)
{
var fraction = (float)i / n;
if (fraction == share)
{
<p>@i/@n = @fraction</p>
success = true;
}
}
}
}
<p>@share</p>```

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Tuesday, November 17, 2015 9:31 AM

### All replies

• User379720387 posted

A loop is not the right tool then.

bool done = false

while(!done)

{

If(test = ok) { done = true;}

}

Monday, November 16, 2015 9:05 PM
• User325035487 posted
```    var share = (float)12 / 13;
bool success = false;
for (var i = 1; i < 100; i++)
{
if (!success)
{
for (var n = 1; n < 100; n++)
{
var fraction = (float)i / n;
if (fraction == share)
{
<p>@i/@n = @fraction</p>
success = true;
}
}
}
}
<p>@share</p>```

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Tuesday, November 17, 2015 9:31 AM