C (gcc), 71 65 bytes
f(char*p){p=*p-'h'?*p&&puts("err"):f(p+1)||!puts("Hello World");}
- 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.
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`program : if `h`h continue recursion and if result is `False`false program do its job. p is `true`true if there was an error, `False`false instead. - if not `h`h stop recursion and : *p - if end of programprogram p is `False`false &&puts("err") - if not end of programprogram display error p is `True`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 !