These are codes that do absolutley nothing, except to show whart you can do with to much time on your hands. Oh the silliness

#include <iostream>

using namespace std;

int main()
{
char a = "H", b = "e", c = "l", d = "l", e = "o", f = ",", g = " ", h = "w", i = "o", j = "r", k = "l", l = "d" , m = "!";

cout<<"\n"<< a << b << c << d << e << f << g << h << i << j << k << l << m <<"\n";

while(1 != 2)
{
return 1;
}
}

the program does what you want it to do so it can't be all that bad.

Edited 5 Years Ago by Clinton Portis: the devil's advocate

the program does what you want it to do so it can't be all that bad.

I'm going to assume that was sarcastic--otherwise, you need to have a serious talk with anyone who has to actually maintain code.

:)

These are codes that do absolutley nothing, except to show whart you can do with to much time on your hands. Oh the silliness

And your point?

well yeah, but it still says hello world the loop is just for laughs and giggles

despite the infinite loop at the end of main().

Actually, its finite, the condition is infinite, but this doesn't necessarily mean the loop is infinite.

The same code but more OOP style:

#include <iostream>
#include <string>

class Application{
private:
 std::string title;
public:
 Application(){}
 Application(const std::string& titleName) : title(titleName){}
 virtual void run() = 0;
 virtual void stop() = 0;
 virtual int exit() = 0;
 const std::string& name()const{ return title; }
 virtual ~Application(){}
};

class MainApplication : public Application{
public:
 MainApplication(): Application(){}
 MainApplication(const std::string& title): Application(title){}
 void run(){ std::cout << Application::name() << endl; }
 void stop(){ }
 int exit(){ return 0; }
};

int main(){
 MainApplication app("hello world");
 app.run();
 return app.exit();
}

>>Actually, its finite, the condition is infinite, but this doesn't necessarily mean the loop is infinite.

True -- the return statement inside the loop will cause the loop to stop after the first iteration.

actually the loop is infinite but the return makes it leave the function thus ending the prorgram. If i did:

while(1 != 2)
{
  cout<<"text\n";
}

it is the same loop with the same parameters (so it is infinite)
but there us nothing to make it leave the loop until 1 = 2 which will never happen

>>actually the loop is infinite but the return makes it leave the function thus ending the program

Actually that loop will never run in the first place because "1 is never equal to 2".

it will run once. it is still an infinite loop because its parameters say that it will happen while 1 != 2. since one will never equal 2, the loop will never end itself, such is the definition of the of an infinite loop. The return one, ends the loop. this doesn't mean it isnt an infinite loop, it just means that the code "force quit" it if you will because that is its job. Imagine the infinite loop as a lung and the brain is the header file. the brain tells the lungs to automatically breathe, even when you aren't concious. now imagine that you live forever but ur in a coma. so the lungs are the infinite loop. but then someone shoots you in a lung and you stop breathing. It is still a lung, but the bullet has stopped it. it is still an infinite loop. just stopped by return 1;
abort(); and good nite

>>It is still a lung, but the bullet has stopped it. it is still an infinite loop. just stopped by return 1;

I think that you put too much "philosophy" into it. An infinite loop is just a loop that runs forever, and so, your loop is not an infinite loop. When you put philosophy into it, you could conclude that all loops are infinite, or you could conclude that no loop is infinite, or you could conclude that there is no such thing as a loop. That's a problem I always had with philosophy, it sometimes asks most irrelevant questions and provides the most useless answers. Programming is about posing concrete problems and finding practical answers. Programming and philosophy don't mix very well.

Food for thoughts, here's another philoso-gramming question: what's the value of a variable that's set but never used?

the proof of a stupid programmer a loop is infinite if the parameters make it so regardless of the code inside

>>the proof of a stupid programmer

Are you suggesting I'm a "stupid programmer"? Not only is that disrespectful and uncalled for, but I can assure that you are wrong (and pretty presumptuous too).

>>a loop is infinite if the parameters make it so regardless of the code inside

What "parameters"? I guess you mean the conditional statements that usually appear either while( /* here */ ) { } , for(; /* here */ ;) { } or do { } while( /* here */ ); . Then, first of all, that code is _inside_ the loop, you can check the C++ standard document if you don't trust me (section 6.5.1/2, in n3242). Second, by your logic, which of these are infinite loops:

//A)
while(true) { 
  break;
};

//B)
for(int i = 0; i < 10; ++i) {
  --i;
};

//C)
foo:
{
  std::cout << "bar" << std::endl;
  goto foo;
}

According to your logic: A) is an infinite loop, B) is not an infinite loop, and C) is not a loop at all.
However, ask any programmer who is worth that title and he/she will tell you that B) and C) are infinite loops and that A) is not. You know, a question like the above could easily be in an exam for an introductory course in programming, this is fundamental stuff (programming 101), it isn't up for debate.

i'm sorry my comments could easily been seen as disrespectful. it will not happen again

I know what the OP is talking about, I have dealt with some pretty nasty code in my time. I think weird problems like always-true loop conditions that only execute once, etc. are rare problems though and they're much easier to fix.

I once took a venture into the Doom Engine to see how much I could improve its display functions. Even some of the most advanced programmers I know agree that it's a complete mess in there. It has a huge dependence on global variables where it should just be passing values, and goto statements, and uselessly dividing an integer only to multiply it later, resulting in unnecessary accuracy loss. It's often difficult to find out which functions are setting which variables, and where some functions get their variables from. When you have such messy code, it's very difficult to extend (or even untangle!).

It's probably a typo but... shouldn't that code give the compiler error: "error C2440: 'initializing' : cannot convert from 'const char [2]' to 'char'"? Due to the use of " instead of ' at row 7, I'm just cursious, in case there is a trick to use " instead, I want to know :)

Edited 5 Years Ago by Fox87: n/a

You could just put this:

while(true)
{
    // Do something
}

Instead of:

while(1 != 2)
{
    // Do something
}