Skip to main content
5 of 6
added 72 characters in body
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58

C (gcc), 71 65 bytes

f(char*p){p=*p-'h'?*p&&puts("err"):f(p+1)||!puts("Hello World");}

Try it online!

  • Thanks to @rtpax for saving 6!
f(char*p){p=  - function tacking a `program` and returning with the eax trick, reusing `p`.
Calls itself recursively.
Recursion happens before `program` execution so if all steps are correct a `false` value is returned and the `program` is executed.
If there's an error a `truthy` value is returned and `program` is not executed at all, an error message is displayed.

*p-'h'? `...` :f(p+1)||!puts("Hello World");
 - check each character in `program` : if `h` continue recursion and
   if result is `False` program do its job.
p is `true` if there was an error, `False` instead.

 - if not `h` stop recursion and :
*p            - if end of program 
p  is `False`
&&puts("err") - if not end of program display error
p  is `True`



61 58 bytes alternative less interesting solution which runs the program and stops when an error happens

f(char*p){*p&&puts(*p-'h'?"err":"Hello World")>4&&f(p+1);}
  • Saved 3 thanks to @rtpax !
AZTECCO
  • 10.9k
  • 1
  • 15
  • 58