Insist on an answer

At runtime, keep prompting for a line of input until the user inputs something (other than an empty newline), i.e. does not just press Enter or OK. Output or result is neither required nor prohibited.

Pseudo-code 1

myform = new form("GUI")
myform.mytxt = new editfield("")
myform.ok = new button("OK")
repeat
waitfor(myform.ok,"click")
until myform.mytxt.content <> ""


Pseudo-code 2

LET TEXT = ""
WHILE TEXT = "" DO
TEXT = PROMPT("")
ENDWHILE


Example 1

Program runs and immediately pops up a form with a single text field and an OK button.
User clicks the OK button.
Nothing happens.
User pastes "hello world" into the text field and clicks the OK button.
Program terminates.

Example 2

Function is called and immediately displays a blank line and a blinking cursor.
User presses Enter.
Cursor moves down one line.
User presses Enter.
Cursor moves down one line.
User presses PPCGEnter
Function returns.

• is it allowed to count space-only lines as empty? – 12431234123412341234123 May 4 '17 at 9:25
• @12431234123412341234123 No. – Adám May 4 '17 at 9:29
• Is it necessary to wait for the full line once the user starts to input data? – Matteo Italia May 7 '17 at 13:22
• Ok, from a comment in @CodyGray's deleted answer it seems like it's not allowed. – Matteo Italia May 7 '17 at 14:54
• @MatteoItalia Yes, correct; a line of input. – Adám May 7 '17 at 15:17

Perl, 15 12 bytes (11 + -n flag)

-3 bytes thanks to manatwork

1/0if$/ne$_


Explanation:

The -n flag places a read loop around the program, turning it into:

LINE:
while (<>) {
1/0 if $/ ne$_  # Spaces added for clarity.
}


Where "<>" reads a line from stdin to the variable $_. If the line contained more than the ending newline (ne is string inequality,$/ is the input record separator which defaults to newline), a division by zero is performed which causes the program to output an error message and terminate.

• Welcome to PPCG. Can you explain your code? – Adám May 4 '17 at 7:05
20 IF NOT LEN A$THEN RUN  Because ZX81 BASIC is tokenised, NOT LEN A$ is a byte shorter then A$<>"". Program lines count 5 bytes each including the line number. • Why can't you use line numbers 1 and 2? – Adám May 5 '17 at 13:03 • @Adám Line numbers are stored internally as 16-bit integers, so they don't affect the byte count. – Neil May 5 '17 at 14:33 Bash + line, 16 bytes [ "line" ]||$0


Backticks are short for $(), to execute a command. line reads a line. If line is empty, then [ will return false, and thus $0 will be executed - the 0th argument which refers to itself. If there is any non-zero string, [ will return true and because of lazy evaluation $0 won't be executed (|| is a logical OR). Notes Instead of line you can also use head -n1, which is more common (but also longer). In all cases I tested for empty lines, which behaves accordingly. And the following special inputs that may break the behavior (but did not ;) ): • -x • aoeu aoeu aoeu • ! The only thing that breaks it is escaping the newline with \, or using a character. But how to handle these special characters is not mentioned in the original question. • Hi, and welcome to PPCG! This seems like an entirely reasonable answer. Sometimes I like to use multiple headers for posts which have multiple answers like this, e.g. "# bash + line, 16 bytes" … "# pure Bash, 19 bytes", but that's optional. Note that if you have dependencies on an external program or library (like line in this case), it helps to mention that in the header. (Also, I think the last solution might break if the user types something like -x? Not sure on that one.) – user62131 May 5 '17 at 11:15 • Thank you, I updated the answer accordingly. The last solution, somehow it didn't work at all. But now I updated it so that it works. I tested all of them and listed which input I tested for. There exist no special parameters that would break anything to my knowledge. – Yeti May 5 '17 at 16:12 • I'd rather you post each answer separately so people (including me) can vote for specific answers. – Adám May 5 '17 at 17:30 • They're now separated, however I'm sure you'll upvote all of them anyway :) – Yeti May 5 '17 at 18:05 Pure Bash, 19 bytes A pure Bash solution using recursion in which a line is read into the variable $a (19 bytes):

read a;[ "$a" ]||$0


Notes

In all cases I tested for empty lines, which behaves accordingly. And the following special inputs that may break the behavior (but did not ;) ):

• -x
• aoeu aoeu aoeu
• !

The only thing that breaks it is escaping the newline with \, or using a character. But how to handle these special characters is not mentioned in the original question.

• Do you need the spaces between the brackets? – OldBunny2800 May 7 '17 at 17:10

x86 Assembler (NASM - Linux), 227 bytes

SECTION .bss
i: resb 5

SECTION .text
global  _start

_start:
mov     edx, 5
mov     ecx, i
mov     ebx, 0
mov     eax, 3
int     80h
cmp byte [ecx], 0xa
je _start
mov     eax, 1
int     80h

• Well done! Nice first answer – Christopher May 6 '17 at 15:43
• Umm, is this really 227 bytes? Usually we count assembler variants based on the size of the compiled outcome. – Erik the Outgolfer May 7 '17 at 14:13

Red, 20 16 Bytes

until[""<>ask""]


Explanation:

until   does the code that's inside the [blocks] until it's true
<>      checks empty string "" isn't returned by rest of code
ask ""  prompts with "" (empty msg), returns user input


Thanks to @endo64 for the code

-4 bytes thanks to @sqlab

• Save 4 bytes by omitting the spaces – sqlab May 5 '17 at 7:59

x86 machine code on DOS, 13 bytes

00000000  43 b4 01 cd 21 3c 0d 75  f7 4b 74 f4 c3           |C...!<.u.Kt..|
0000000d


Commented assembly:

    org 100h

section .text

; notice: on virtually every DOS bx starts at 0 at program start
; see http://www.fysnet.net/yourhelp.htm
start:
inc bx      ; bx counts the number of read characters; increment it
mov ah,1
int 21h     ; read a character into al
cmp al,0dh  ; check if it's a newline
jne start   ; repeat if it's not
dec bx      ; got a newline; decrement the counter
jz start    ; if the counter became 0, it means that we only read the
; newline; restart (with bx being 0, as on startup)
ret         ; otherwise quit


QBasic, 34 bytes

INPUT A$WHILE A$=""
INPUT A$WEND  I think nothing can be more self-explanatory than that. To test, go to this website and copy-paste the following code in their text-editor : 10 INPUT A$
20 WHILE A$="" 30 INPUT A$
40 WEND


The reason why line numbers are required is that their website only supports unstructured BASIC.

• Why the final END? – Adám May 4 '17 at 4:59
• @Adám The final END is required to terminate the program when the interpreter comes out of the while loop (WEND is to terminate While Loop) – Arjun May 4 '17 at 5:13
• So what happens if there is no more program to execute, even though END hasn't been reached? – Adám May 4 '17 at 5:14
• @Adám According to the standard, a program must have an END statement as the last statement. However, many interpreters don't require it. But I will keep it just for the sake of compatibility. – Arjun May 4 '17 at 5:22
• This has been discussed on Meta, concluding that a language is defined by its implementation, not its documentation. – Adám May 4 '17 at 5:26

C#, 36 bytes

_=>while(System.Console.Read()==13);


Compiles to a Action<int>.

Or if a full program is required, 62 bytes.

class P{static void Main(){while(System.Console.Read()==13);}}


Batch, 35 bytes

@set s=
@set/ps=
@if "%s%"=="" %0


Rather unfortunately, Batch doesn't clear the variable if you don't enter anything.

• I guess this crashes if %s% == " – stevefestl May 7 '17 at 7:08
• @SteveFest Indeed, but it still stops insisting on an answer... you can probably crash-resist it by using %s:"=""%. – Neil May 7 '17 at 9:12
• It would make a error message without the replace... Which is unnecessary – stevefestl May 7 '17 at 9:13

Lithp, 90 bytes

((import readline)(readline "?" #A::((f A)))(def f #A::(if(== "" A)((readline "?"(get f/1)


Try it online! (Also works on command line in node)

A side effect of the current parser is that not all trailing ) brackets are required. The very last one is, but the rest can be omitted saving quite a few bytes.

The readline module works in browser and via command line, and uses a callback. We exploit this to call readline before defining f, and save many bytes not needed all the closing brackets to invoke f after it's defined.

Kotlin, 3835 29 bytes

-3 bytes by negating any() rather than calling isEmpty()
-6 bytes thanks to Adám pointing out the function doesn't need to be named to be called

{while(!readLine()!!.any());}


called like so:

{while(!readLine()!!.any());}()


Try it online!

• Something wrong with your TIO link. – Adám May 4 '17 at 11:57
• You just have to click the click here link to remove the message about TIO v2 – The_Lone_Devil May 4 '17 at 11:58
• In that case you could just link to tio.run/nexus, but why not fill in the necessary fields on tio.run/nexus/kotlin and get the full URL (hint: press Esc, S)? – Adám May 4 '17 at 12:00
• @Adám Updated the link to use tio.run/nexus, never used TIO before :) – The_Lone_Devil May 4 '17 at 12:02
• Nice. I think you only have to count the 29 char brace, as the function does not need to be named in order to be called. – Adám May 4 '17 at 12:06

AHK, 19 bytes

While !a
InputBox,a


Not very interesting, I'm afraid.

Ruby, 19 bytes

while gets==?\n;end


Scala, 21 bytes

while(readLine==""){}


Scala can run code as a script without the need for a class/main method so this is a complete program.

readLine is deprecated since Scala 2.11 but it's still available in 2.12

QBIC, 7 5 bytes

≈A|_?


Saved 2 bytes because empty string is falsy.

Explanation:

≈ |     WHILE <condition>
A      A$gets set by _? below. Empty string is false, so it stays in the WHILE _? Ask the user for input, implicitly assign to A$


Mathematica, 20 bytes

While[Input[]==Null]


REXX, 24 bytes

do until n>''
pull n
end


Tcl, 26

while {![gets stdin t]} {}


demo

Excel VBA 25 bytes

while Inputbox(0)="":wend


You can run it via immediate window. It's a simple while loop with inputbox.

Pure Bash, 21 bytes

A pure Bash solution using shift and recursion with parameter (21 bytes):

shift||(read a;$0$a)


shift shifts the arguments (and defaults to shifting 1). Which fails if there is no argument, upon which it will try to execute itself again with the next read line as the first argument.

Note that double quotes are here not needed if the line contains spaces, because it does not matter if it's just one word or multiple.

Notes

In all cases I tested for empty lines, which behaves accordingly. And the following special inputs that may break the behavior (but did not ;) ):

• -x
• aoeu aoeu aoeu
• !

The only thing that breaks it is escaping the newline with \, or using a character. But how to handle these special characters is not mentioned in the original question.

Bash + line, 16 bytes

Another approach using recursion with parameter (16 bytes), using shift:

shift||\$0 line


shift shifts the arguments (and defaults to shifting 1). Which fails if there is no argument, upon which it will try to execute itself again with the next read line as the first argument.

Notes

Instead of line you can also use head -n1, which is more common (but also longer).

In all cases I tested for empty lines, which behaves accordingly. And the following special inputs that may break the behavior (but did not ;) ):

• -x
• aoeu aoeu aoeu
• !

The only thing that breaks it is escaping the newline with \, or using a character. But how to handle these special characters is not mentioned in the original question.

Pyke, 2 bytes

W!


Try it online!

See the debug output to show it's actually reading input

W  - do v
! -  not(input())
- while ^


Javascript, 17 bytes

for(;!prompt(););


A for alternative to the while answer already here

C, 83 bytes

e(char*t){*t>32?1+e(t+1):0;}
f(){size_t l;char*t;getline(&t,&l,stdin)+1&&e(t)&&f();}


The above answer will read full lines, and check if the read line has content beside spaces\tabs.

shorter non-conforming version, 23 bytes

f(){getchar()-10?:f();}


Java, 79 bytes

boolean f(){System.console().readLine().replaceAll("\\t| ","").isEmpty()&&f();}


The above answer will read full lines, and check if the read line has content beside spaces\tabs.

shorter non-conforming version, 38 bytes

void f(){if(System.in.read()==10)f();}


VBScript, 26 bytes

while InputBox("")=""
wend


This one is sort of fun because the only way to stop the programs asking for an answer is either giving one or killing 'wscript.exe' in the task manager.