私はgotoステートメントを使用するプログラムを書き直すという仕事を与えられました。それは、いかにイライラさせることができるかを示す唯一の目的であり、実際には非常にイライラしていることが分かりました。私はまだ問題に遭遇しているデバッガをフリップして数時間後、私は潜在的にそれをよりよく理解することができる私のためにこれを擬似コードできる人はいますか?それぞれのgotoのif文とelse文を作成することとは別に、私は失われています。GoToプログラムのSudoコード
namespace Assignment_03_Nasty_Code
{
class Assignment03
{
static void Main(string[] args)
{
Console.WriteLine("Assignment 03 = " + new Assignment03().Solve());
}
public int Solve()
{
int result = 0;
int upperSearchLimit = 1_000_000;
Console.WriteLine("Building list of primes...");
ArrayList primes = Utils.BuildListOfPrimes(upperSearchLimit);
Console.WriteLine(" Done.");
// Step through the odd composite numbers
for (int i = 19; i < upperSearchLimit; i+= 2)
{
Label02:
if (primes.Contains(i))
goto Label03;
// Is the number divisible by a prime?
int j = 0;
Boolean match = false;
Label01:
int tmp;
int prime = (int)primes[j];
tmp = i - prime;
int half = tmp /= 2;
int squareRoot = (int) Math.Sqrt(half);
if (tmp != squareRoot * squareRoot)
goto Label04;
// We got one
//System.out.println(i + " is a composite that can be written as the sum of a prime and twice a square");
match = true;
Console.WriteLine(i + " = " + (int)primes[j] + " + 2 * " + half);
Label04: // Second goto
j++;
if ((int)primes[j] < i)
goto Label01;
if (match == false)
{
Console.WriteLine("No match for " + i);
result = i;
break;
}
//goto Label02;
Label03: // First goto
int x;
}
return result;
}
}
}
まず最初は、フォーマッタてコードを実行することになる結果です! –
そのような目的を破ったのですが、やはり私はゴートステートメントを決して使わないように教えることを目的としていたと思います。 – shockemc
"goto"ステートメントは、これらの問題の1つにすぎません。字下げを修正することを意味していましたが、 "テキストの壁"は不必要に難しいです。インデントを修正してから、gotoを扱います。 –