Hello World

A

August Derleth

Wrong. It's

#include <stdio.h>

int main ()
{
puts ("Hello World!");
return 0;
}

Or, if you want to annoy someone:

#include <stdio.h>

int main(void)
{
do { puts("Hello, world!"); } while(1);
return 0;
}

;)

(Interestingly, more than a few programming examples seem to think the
Hello, world! program /should/ be an infinite loop. I have no idea why.)
 
C

CBFalconer

August said:
.... snip ...

#include <stdio.h>

int main(void)
{
do { puts("Hello, world!"); } while(1);
return 0;
}

Since the return never gets executed, is the program correct under
C90 if the line is elided?

Chuck, making trouble.
 
O

Old Wolf

August Derleth said:
Or, if you want to annoy someone:

#include <stdio.h>

int main(void)
{
do { puts("Hello, world!"); } while(1);
return 0;
}

I think the "return 0;" is superfluous here (and may even generate
a compiler warning for unreachable code).
(Interestingly, more than a few programming examples seem to think the
Hello, world! program /should/ be an infinite loop. I have no idea why.)

10 PRINT "HELLO"
20 GOTO 10
 
M

Mabden

Old Wolf said:
I think the "return 0;" is superfluous here (and may even generate
a compiler warning for unreachable code).


10 PRINT "HELLO"
20 GOTO 10

Because there are so many people in the World...?
 
G

Guillaume

(Interestingly, more than a few programming examples seem to think the
Hello, world! program /should/ be an infinite loop. I have no idea why.)

That's called flooding. ;)
 
D

Dan Pop

In said:
Since the return never gets executed, is the program correct under
C90 if the line is elided?

Most definitely yes. Depending on your particular definition of program
correctness, it could be *always* elided: its removal doesn't invoke
undefined behaviour and doesn't require a diagnostic.
Chuck, making trouble.

Failed attempt ;-)

Dan
 
F

Fao, Sean

Old said:
I think the "return 0;" is superfluous here (and may even generate
a compiler warning for unreachable code).




10 PRINT "HELLO"
20 GOTO 10

Funny how a simple, probably troll, post can yield a discussion in it of
itself.
 
J

Joe Wright

Old said:
I think the "return 0;" is superfluous here (and may even generate
a compiler warning for unreachable code).




10 PRINT "HELLO"
20 GOTO 10

10 PRINT "GOODBYE"
20 GOSUB 10

It's been a long time..
 
I

Irrwahn Grausewitz

August Derleth <[email protected]> wrote:.

10 PRINT "HELLO"
20 GOTO 10

program Nikolaus;

var
there_is_a_cold_day_in_hell : integer;

begin
there_is_a_cold_day_in_hell := 0;
repeat
writeln('Wotsit Wirth');
until there_is_a_cold_day_in_hell;
end.

<g,d&rf>

Regards
 
J

Joona I Palaste

program Nikolaus;
var
there_is_a_cold_day_in_hell : integer;
begin
there_is_a_cold_day_in_hell := 0;
repeat
writeln('Wotsit Wirth');
until there_is_a_cold_day_in_hell;
end.

Unlike C, Pascal has an explicit boolean type, and does not implicitly
convert integers into booleans. Therefore the above code won't even
compile.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
 
I

Irrwahn Grausewitz

Joona I Palaste said:
var
there_is_a_cold_day_in_hell : integer; [...]
until there_is_a_cold_day_in_hell;
[...]

Unlike C, Pascal has an explicit boolean type, and does not implicitly
convert integers into booleans. Therefore the above code won't even
compile.

You're right; my Pascal days are long since over, and I had to think
hard to recall at least some of its obtuse syntax. 'Twas a silly joke
anyway...

Regards
 
C

CBFalconer

Irrwahn said:
<snip>

program Nikolaus;

error: use "program Nikolaus(output);"
var
there_is_a_cold_day_in_hell : integer;

should be: "there_is_a_cold_day_in_hell : boolean;"
begin
there_is_a_cold_day_in_hell := 0;

should be: "there_is_a_cold_day_in_hell := false;"
(alternative - modify the 'until' statement - less clear)
repeat
writeln('Wotsit Wirth');
until there_is_a_cold_day_in_hell;
end.

<g,d&rf>

and it should now pass the compiler. <running>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Print('hello world') not working? 3
Hello World 1
Hello World 2
HELLO 2
Hello world 1
Hello World 0
Hello world 1
Hello 2

Members online

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top