[Question]
  [
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
 
 
---
 This question does not appear to be about code golf or coding challenges within the scope defined in the [help center](https://codegolf.stackexchange.com/help/on-topic).
Closed 7 years ago.
**Locked**. This question and its answers are [locked](/help/locked-posts) because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
 
 
Write a script that works fine when a blank line is present in the flow of program logic, but breaks or causes unexpected behaviour when that line is removed.
Avoid [standard loopholes](http://meta.codegolf.stackexchange.com/q/1061) and stupid answers. Your program should do something "useful," even if all it does is add a few integers.
Removing an empty line from a multiline string doesn't count, unless the expected output from that multiline string shouldn't technically change (ie: if you're removing all blank lines matching `^$`).
Whitespace foolery isn't allowed either; don't do weird things with carriage returns, tabs, spaces, etc.
  
[Answer]
# Javascript
Opens an alert popup with "Hello, World!" if the blank line exists, otherwise alerts "0".
```
(function(){
    alert(~(arguments.callee+[]).indexOf('\n\n') && "Hello, World!");
})();
```
**[Demo](http://jsfiddle.net/fs7C9/)**
**Explanation:**
`arguments.callee` is a reference to the self-executing anonymous function.
Appending a blank array (`[]`) casts the function to a string, which gives you its source code.
`indexOf` returns `-1` if the string is not found. 
Performing a bitwise not operation (`~`) results in `-1` being turned into `0`, which is a falsey value.
[Answer]
# C
This magic 8-ball program will still work without the blank line, but it will be a bit more decisive — none of the neutral answers will ever appear in the output.
```
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main() {
  int x, t;
  char *quotes[] = {
        // Positive :-)
        "It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it",
        "As I see it, yes", "Most likely", "Outlook good", "Yes", "Signs point to yes",
        // Indifferent :-\
        "Reply hazy try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again",
        // Negative :-(
        "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful" };
  srandom(time(NULL)); // Initialize random number generator
  x = random() % (sizeof(quotes) / sizeof(char*)); // Choose a random outcome
  printf("The Magic Eight Ball says...\n%s\n",quotes[x]);
  return 0;
}
```
### Explanation
> 
>  When the C parser sees a backslash followed by a newline character, it ignores both and treats the second line as a continuation of the first. Without the empty line, the "indifferent" answers will all be treated as part of the previous comment.
> 
> 
> 
[Answer]
# Befunge-93
```
v
&
&
+
#
.
@
```
My first befunge program :)
It reads two numbers from the input and prints their sum. If you delete the empty line, it doesn't print anything.
**Explanation:**
`v` sets a downward direction for executing the code  
`&` reads an integer  
`+` adds the numbers together  
`#` skips the next command  
`.` prints an integer from the stack  
`@` ends the program
As written, `#` skips over the empty line and contines with `.`. Buy when you delete the empty line, `.` is skipped.
There seems to be a nice interpreter at <http://befunge.aurlien.net/>
[Answer]
# Ruby/Shell
```
​​​​​​
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#!   The Amazing Integer Adder             !
#! Adds 1 and 1, and displays the result   !
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
p 1+1
```
Works fine if a newline is at the top, otherwise the first comment line is interpreted by the shell as a malformed shebang.
[Answer]
# Scala
```
case class IntWrapper(i: Int)
{
  val answer = (IntWrapper(0) /: (1 to 100)){(x, y) => IntWrapper(x.i + y)} // Add up ints
  println(s"Sum of wrapped integers is $answer")
}
```
If you remove the blank line, no output will be printed. Which is for the best, as your stack would overflow if you actually called `IntWrapper`.
> 
> This is a corner case of Scala's semicolon inference. Normally newlines get a semicolon whenever the resulting code would be valid. However, the Scala devs didn't want to force people to use [Egyptian brackets](http://blog.codinghorror.com/new-programming-jargon/), so it's valid to put the brackets for a class definition on the line immediately after - no semicolon is added, even though one could be. However, a blank line divorces the brackets from the class definition. With the blank line removed, the code changes from being a class definition and a block, to a class definition with a constructor - and a recursive constructor at that!
> 
> 
> 
[Answer]
# GolfScript
```
~{.@\%:
}do;
```
Calculates the GCD of two non-zero integers. Removing the blank line breaks the program.
[Try it online.](http://golfscript.apphb.com/?c=IjE1IDI0IiAjIFNpbXVsYXRlIGlucHV0IGZyb20gU1RESU4uCgp%2Bey5AXCU6Cgp9ZG87)
### How it works
This is a GolfScript implementation of the Euclidean algorithm:
```
      # STACK: "15 24"
~     # Interpret the input string.
{     # STACK: 15 24
  .@  # Duplicate the topmost integer and rotate the other on top of both copies.
      # STACK: 24 24 15
  \   # Swap the topmost integers.
      # STACK: 24 15 24
  %   # Calculate the modulus.
      # STACK: 24 15
}do   # If the modulus is non-zero, repeat the loop.
;     # Discard the last modulus.
```
There's just one tiny problem:
> 
>  `{}do` pops the modulus from the stack to check if it's truthy, so it has to get duplicated at the end of the loop. This is normally accomplished by `.`, but `:\n\n` has the same effect: It stores the topmost stack item in the variable LF (`:\n`), then pushes the contents of that variable. 
> 
> 
> 
[Answer]
## MediaWiki Template Syntax
Define Template:Foo as
```
{{{a
b|Uh-oh!}}}
```
In another page,
```
{{Foo|a
b=Works!}}  <!-- outputs "Works!" -->
{{Foo|a
b=Works!}}  <!-- outputs "Uh-oh!" -->
{{Foo|a
b=Works!}}  <!-- outputs "Uh-oh!" -->
```
> 
>  In MediaWiki, parameter names can contain newlines.
> 
> 
> 
[Answer]
# LaTeX (backref)
The following LaTeX code uses a citation and the citation contains a list of pages, where the entry is citated. Here it is the first page. Package `hyperref` also adds PDF links, the page back reference is red, the citation link is green.
```
\documentclass{article}
\usepackage[colorlinks,pagebackref]{hyperref}
\begin{document}
Donald E. Knuth is the inventor of \TeX~\cite{knuth}.
\begin{thebibliography}{9}
\bibitem{knuth}
Donald E. Knuth: \textit{The \TeX book}; Addison Wesley, 1984.
\end{thebibliography}
\end{document}
```
> 
> ![Result](https://i.stack.imgur.com/DAE0n.png)
> 
> 
> 
But LaTeX does not require the empty line, the empty line looks superfluous and the example will still work without `hyperref` and the empty line:
```
\documentclass{article}
\begin{document}
Donald E. Knuth is the inventor of \TeX~\cite{knuth}.
\begin{thebibliography}{9}
\bibitem{knuth}
Donald E. Knuth: \textit{The \TeX book}; Addison Wesley, 1984.
\end{thebibliography}
\end{document}
```
> 
> ![Result without hyperref](https://i.stack.imgur.com/BqE8G.png)
> 
> 
> 
But the links and back reference are gone, thus we reinsert them:
```
\documentclass{article}
\usepackage[colorlinks,pagebackref]{hyperref}
\begin{document}
Donald E. Knuth is the inventor of \TeX~\cite{knuth}.
\begin{thebibliography}{9}
\bibitem{knuth}
Donald E. Knuth: \textit{The \TeX book}; Addison Wesley, 1984.
\end{thebibliography}
\end{document}
```
But now the example is **broken** and will **not compile** anymore:
```
Runaway argument?
 Donald E. Knuth: \textit {The \TeX book}; Addison Wesley, 1984. \end \ETC.
! File ended while scanning use of \BR@@bibitem.
<inserted text> 
                \par 
<*> knuth
?
```
What happened? Package `hyperref` (or more precise package `backref`, which is loaded by `hyperref`) wants to get at the end of the bibliography entry to add the back reference list. But the syntax in LaTeX only provides the beginning of the entry by `\bibitem`, the end can be anywhere. In this emergency package `backref` has added a restriction that `\bibitem` has to end the entry with an empty line. Then the package can redefine `\bibitem` to put the back references at the end of the entry.
Since the empty line is missing, TeX keeps looking for it, but found the end of file instead and issues the error message.
[Answer]
# C (semi-obfuscated)
This little program takes a number on the command line and computes its factorial. However, it also contains cutting-edge AI functionality for runtime verification that the company's coding standards, including the correct use of whitespace and blank lines, are being followed. Removing a blank line will trigger the algorithm to reject the insufficiently maintainable program.
No line continuations or trigraphs anywhere. I believe it is valid ANSI C99.
Due to the advanced mathematics involved, if you compile with `gcc`, remember to use `-lm`.
```
#include <setjmp.h>
#include <stdio.h>
#define max(x,y) ((x<y?y:x))
#define swap(x,y) ((x^=y,y^=x,x^=y))
#include <stdlib.h>
#include <math.h>
#define vfry(x,p,z,y,i) (!!y&((z##z##L##I##p##x##z##z)))
#define NDEBUG
/* 
 * Proper use of whitespace is essential!
 * Please do not remove any blank lines.
 */
const double E = 2.71828182845904523536;
int vrfy(double epsilon, int magic, const char *key, long int L) {
  /* You are not expected to understand this */
  double x=284.2891,u=2.34e56;
  while (rand()+magic*pow(epsilon,sin(x-E))!=log(u*L))
    x*=vrfy(1.0/epsilon,(int)u,&key[swap(L,magic)],L++);
  return u/lgamma(x);
}
int main(int argc, char *argv[]) {
  int N_=831293812; /* do not change, see Knuth 1987 */
  if (!vfry(E, N,_, "M=&;VT=I!9", 0xfe86ddcaL)) {
    fprintf(stderr, "Code standards violation detected!\n");
    abort();
  }
  if (argc < 2) {
    fprintf(stderr, "Usage: %s n\nComputes n!\n", argv[0]);
    exit(1);
  }
  int m=1, n=atoi(argv[1]), i;
  for (i=1; i <= n; i++)
    m *= i;
  printf("%d! = %d\n", n, m);
  return 0;
}
```
# Spoiler
> 
>  The complicated `vrfy` function is never called, but rather the funny-looking `vfry` macro. The use of the preprocessor's [string concatenation feature](http://gcc.gnu.org/onlinedocs/cpp/Concatenation.html) disguises the fact that we are really just checking the parity of `__LINE__`.
> 
> 
> 
[Answer]
# C
This program works as expected (as described in the comments) unless the blank line before `foo = 5;` is removed.
Sadly, I encountered an error almost exactly like this in production code once.
```
#include <stdio.h>
int main()
{
    int foo = 0;
    #define FROB(x) do {                                            \
        x++;                                                        \
        printf("%d\n", x);                                          \
    } while (0);                                                    \
    foo = 5;
    FROB(foo); /* prints 6 */
    FROB(foo); /* prints 7 */
    FROB(foo); /* prints 8 */
    return 0;
}
```
This example uses the `do { ... } while (0)` idiom for creating a multiline statement in a macro (see <https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for>). It also uses the backslash character to spread a `#define` over multiple lines, conveniently lined up well out of sight. However, it also does two things kind of wrong:
* There is a semicolon after `while (0)`, while the idiom usually omits this
* There is a backslash after the final line of the `#define`
With this in place, removing the blank line before `foo = 5;` causes that assignment to be executed *after* the `printf`, but also after *every* invocation of the `FROB` macro. As a result, the output after removing the blank line is:
```
1
6
6
```
[Answer]
# C/C++
```
int main(){
    return __LINE__ - 3;
}
```
Returns success and can be used as an implementation for [true](http://ss64.com/bash/true.html). If the empty line is removed you can use it as an implementation for [false](http://ss64.com/bash/false.html) instead.
[Answer]
## PowerShell
This function will add two numbers.
```
function add ($a, $b) {
    $numbers = @($a `
            $b)
        $numbers| measure -sum| select -expand sum
}
```
Removing the blank line will cause the function to fail with: `Unexpected token '$b' in expression or statement.`
**Explanation**
> 
> Array elements can be separated by newlines and/or commas. Placing the line continuation character (```) after `$a` requires an extra newline to separate `$a` and `$b`. Otherwise, the interpreter views the code as `$numbers = @($a $b)` (no element separator).
> 
> 
> 
[Answer]
## TeX
```
\noindent\everypar{$\bullet$ hello }
world
\bye
```
Without the empty line, "hello" is not printed.
**Explanation**
TeX treats the empty line as a paragraph break, and `\everypar` is executed at the start of a new paragraph.
[Answer]
# Java
```
import java.util.Scanner;
public class BlankLine
{
    public static void main( String[] args )
    {
        //This calculates 2^ given number
        //if you remove blank line after the next line it will always print 1
        int x = new Throwable().getStackTrace()[0].getLineNumber();
        int y = new Throwable().getStackTrace()[0].getLineNumber() - x;
        System.out.println("Number:");
        Scanner scanner = new Scanner(System.in);
        int r = 1;
        int n = scanner.nextInt();
        for(int i = 0; i < n; i++){
            r *= y;
        }
        System.out.println("2^number: "+r);
    }
}
```
> 
>  x is current line number, y is current line number - x. If there is blank line between them the result is 2. So the code calculates 2 ^ number.
> 
> 
> 
[Answer]
# Perl 5
```
print(<<""
Hello, World!
);
```
This code prints `Hello, World!`. Removing the blank line gives a syntax error instead.
Explanation:
> 
>  Perl's [here-doc syntax](http://perldoc.perl.org/perlop.html#%3C%3CEOF) for multi-line strings allows an empty terminator string. It's even explicitly documented. Removing the blank line causes the closing parenthesis (and everything else up to the next blank line, if there is one) to be interpreted as part of the string, causing a syntax error.
> 
>  The error messages you get are actually pretty decent, for such an oddball syntax feature. If there are no blank lines at all in the program after the `print(<<""` line, Perl simply says:
> 
>  
> ```
> Can't find string terminator "" anywhere before EOF at foo.pl line 1.
> ```
> 
> If there *is* an empty line at the end of the program, you get something like this instead:
> 
>  
> ```
> syntax error at foo.pl line 4, at EOF
>   (Might be a runaway multi-line << string starting on line 1)
> Execution of foo.pl aborted due to compilation errors.
> ```
> 
> 
> 
> 
> 
> 
> 
> 
[Answer]
## Batch
```
@echo off
setLocal enableDelayedExpansion
set NL=^
echo Hello!NL!World
```
This code will output `Hello` and on the next line `World`. When either or both of the blank lines are removed, it outputs nothing at all.
[There is an explanation here](https://stackoverflow.com/questions/6379619/explain-how-dos-batch-newline-variable-hack-works/6379861#6379861).
[Answer]
# Ruby
Deletion of the first line will cause error:
`line = IO.readlines($0).first.chomp
if line.empty?
puts 34+4
else 
raise "Please add a newline at the beginning of the program."
end`
[Answer]
# Python
Don't know if this falls under the standard loopholes, I looked at the list and didn't see this. 
```
src = open(__file__, 'r')
code = src.readlines()
src.close()
if code[3] == '\n':
    print 'Hello World!'
```
Running this regularly returns
```
Hello World!
```
Running it without the blank line on line 4, ie like below:
```
src = open(
__file__, 'r')
code = src.readlines()
src.close()
if code[3] == '\n':
    print 'Hello World!'
```
returns nothing. 
[Answer]
# Python 2.x
This program outputs the fifth character of the inputted string.
```
import inspect
text = raw_input()
print 'Fifth character of the string:', text[inspect.getlineno(inspect.currentframe())]
```
This isn't in any way hidden. If you remove the empty line, it gives the fourth character and the sixth if you add one.
[Answer]
## Tcl
A function that adds two numbers (and checks if the newline have been deleted):
```
proc add {a b} {
    if {[llength [split [info body add] \n]] < 5} {error "function has been modified"}
    return [expr $a+$b]
}
```
There's nothing to hide here, it does what it says, so I'm not spoilerizing the explanation. The function `info` is a swiss army knife of introspection (what other languages call reflection). `info body` returns the source code of a function (if not written in C or assembly).
I have to admit that this had me stumped until I saw the javascript solution.
[Answer]
# C
```
#include <stdio.h>
int main() {
    const char* a = "You love blank lines.";
    #define print_out(a) \
    printf("%s\n", a);
    a = "You don't seem to love blank lines";
    print_out(a);
    return 0;
}
```
With the blank line, `a` is the local variable a and without it's the macro parameter...
[Answer]
Technically not a "code" issue, but a server one. If this is sent to Apache from a CGI script (which can be generated with any language you please), it will send an HTTP response to the client:
```
HTTP/1.x 200 OK 
Content-Type: text/html; charset=UTF-8
Hello world!
```
On the other hand, this will fail as it is missing the blank space after the header.
```
HTTP/1.x 200 OK 
Content-Type: text/html; charset=UTF-8
Hello world!
```
[Answer]
**JavaScript**
The function `whereami` responds with the position of the calling line, relative to its own position in the source code.
```
console.log (whereami ()) //3 line(s)  before me 
function whereami () {
    var a=function a(e){try{to}catch(c){for(var d=c.stack.split("\n"),b=0;b<d.length&&!~d[b].indexOf("a");b++);return c.stack.split("\n")[b+~~e].match(/:(\d+)/)[1]-~~window.hasOwnProperty("__commandLineAPI")}},a1=a(1),i
    i= a(2)>a(1)+4?a(1):a(1)>a1+2?a1-1:a/a1
    return ((i=(a(2)<i?i-1:a(1)>i+3?a(2)-a(1)-1:a/1)) + " line(s) "   ) + (i<a(2)?" after":(i>=a(2)?" before":"confusing")) + " me";
}
console.log (whereami ()) //3 line(s)  after me
```
If any blank line in the `whereami` function is removed. The output is `NaN line(s) confusing me`. *(Adding lines doesn't break it)*
> 
>  It actually only counts how many lines are between `i` and the first and last line respectively. If they fall under a given value. The reference line is set to `NaN` which neither satisfies `NaN<callingLine` nor `NaN>=callingLine`. I tried to hide it a bit in unreadable ternary expressions.
> 
> 
> 
[Answer]
# Perl
```
#!/usr/bin/perl
use strict;
use warnings;
open IN, "<".$0 or die "Did not find input files!";
while (<IN>) {
        m/blabla/ && ((<IN> =~ /\}/ && print "tra-la-la...\n") || print "ti-ri-li\n");
}
close IN;
```
> 
>  This perl script will read the script file and check if after the line containing "blabla" there is a closing bracket.
> 
> 
> 
[Answer]
## Escript
Due to bug in `escript` implementation valid escript has to be at least three lines long and first line hast to be shebang line or empty line. So following script hast to have two empty lines where first one has to be first one:
```
main(_) -> io:format("Hello world!~n", []), halt().
```
Or it hast to be broken in two lines but still has to have first empty line.
```
main(_) ->
    io:format("Hello world!~n", []), halt().
```
Otherwise you will get
```
escript: Premature end of file reached
```
[Answer]
# Ruby
```
print %q
2+2=
p(2+2)
```
Prints `2+2=4`, but gives a syntax error without the blank third line. `%q` allows any non-word character to serve as a string delimiter, even the newline character. So the first three lines of code are actually equivalent to `print %q"2+2="`, or just `print "2+2="`. Since the newline after `2+2=` is being used as a quote delimiter, it's not also parsed as a *line* delimiter, so you need another one immediately after.
[Answer]
# Insomnia (both versions)!
```
Þyoo
â
```
This code prints a ~ (don't ask why, insomnia is weird). If you remove the blank line, it prints a ÿ instead.
By the way that first letter is a [thorn](https://en.wikipedia.org/wiki/Thorn_(letter)).
[Answer]
## C++
This is a classic and rather dumb trick. You will know what it is when you see it, this is just here for completion's sake. As such, I'm marking this as a community wiki answer.
```
int main() {
    //This program won't work without the next line, why??/
    return 1;
}
```
[Why this works](http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C)
[Answer]
Paste this into a html file, and open it in your browser. It's pretty simple, but a little tricky because it takes the number of blank lines in the document and indexes an array to call a function which shows an alert.
```
<body>
<script>
[null, function(){alert("GIVE ME MY LINE BACK")}, function(){alert("2 + 2 = " + (2+2))}][document.body.innerHTML.split("\n\n").length]()
</script>
</body>
```
This one is borderline rule breaking. Technically JavaScript doesn't have multiline strings, which is the only reason this works. 
Because you can have a syntax error in one script tag without interfering with the other script tags this shows a positive result only if there's an error on the page. The error prevents the second alert from firing because it's in the same script tag.
```
<body>
<script>
window.onerror=function(){
  alert("2 + 2 = " + (2+2));
}
</script>
<script>
var a = "\
";
alert("GIVE ME MY LINE BACK!");
</script>
</body>
```
[Answer]
Ruby
```
puts (% #{ARGV[0].to_i + ARGV[1].to_i}
)
```
The secret is that the newline, is really a tab, then a new line. I don't know if this counts but I thought it was cleaver. The character after the `%` is also a tab, but for some reason it doesn't show up like one. I'm using Ruby's percent notation to make a string, that adds the first 2 arguments passed to the script. There's more on that here:
<http://teohm.com/blog/2012/10/15/start-using-ruby-percent-notation/>
]