Re: Alternatives for "if"
Quote:
Originally posted by criticalerror
I have a project that specifies that we cannot use if statements.
As a rule, whatever can be done using ifs, whiles, fors, and the like can be done using the much more elegant goto statement. Of course, you'll still need to use one of those constructs--or inline assembly--to complement the goto.
Code:
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 6;
while (a < b)
goto bob;
goto death;
bob:
cout << "Bob has been executed." << endl;
death:
cout << "Now dead and buried." << endl;
return 0;
}
Re: Re: Alternatives for "if"
Quote:
Originally posted by UnregdRegd
As a rule, whatever can be done using ifs, whiles, fors, and the like can be done using the much more elegant goto statement. Of course, you'll still need to use one of those constructs--or inline assembly--to complement the goto.
Code:
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 6;
while (a < b)
goto bob;
goto death;
bob:
cout << "Bob has been executed." << endl;
death:
cout << "Now dead and buried." << endl;
return 0;
}
Why use a statement its own creators abhor. The goto statement is there to wean you off BASIC or FORTRAN, IMHO. It doesn't support modular programming concepts and is "infinetly abusable" why fall back on bad habits. Besides The conditional operator is succint and in some cases can even increase performence.