Input loop: Difference between revisions

m
m (syntax highlighting fixup automation)
imported>Arakov
 
(8 intermediate revisions by 7 users not shown)
Line 519:
 
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="ml/iarturo"></syntaxhighlight>while [true][
i: input "> "
print i
]</syntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 1,283 ⟶ 1,290:
 
=={{header|Elena}}==
ELENA 46.x:
 
Using ReaderEnumerator
Line 1,292 ⟶ 1,299:
public program()
{
ReaderEnumerator.new(File.assign:("file.txt")).forEach(printingLn)
}</syntaxhighlight>
Using loop statement
Line 1,299 ⟶ 1,306:
public program()
{
using(var reader := File.assign:("file.txt").textreader())
{
while (reader.Available)
Line 1,492 ⟶ 1,499:
 
HandleEvents</syntaxhighlight>
 
=={{header|GDScript}}==
{{works with|Godot|4.0.1}}
 
<syntaxhighlight lang="gdscript">
extends MainLoop
 
 
func _process(_delta: float) -> bool:
while true:
# Read a line from stdin
var input: String = OS.read_string_from_stdin()
 
# Empty lines are "\n" whereas end of input will be completely empty.
if len(input) == 0:
break
printraw(input)
return true # Exit
</syntaxhighlight>
 
=={{header|gnuplot}}==
Line 1,648 ⟶ 1,674:
=={{header|J}}==
Script "read-input-until-eof.ijs":
<syntaxhighlight lang="j">#!/Applications/j602usr/bin/jconsoleijconsole
NB. read input until EOF
((1!:1) 3)(1!:2) 4 NB. tested under j602
exit ''</syntaxhighlight>
Example:
Line 2,176 ⟶ 2,202:
The very nature of ML/I is that its default behaviour
is to copy from input to output until it reaches end of file.
<syntaxhighlight lang="ml/i"></syntaxhighlight>
 
=={{header|Modula-2}}==
Line 2,518 ⟶ 2,543:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</syntaxhighlight>-->
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/Input_loop
by Galileo, 10/2022 #/
 
include ..\Utilitys.pmt
 
def eof? dup -1 == enddef
 
"input.txt" "r" fopen
( inf 0 -1 ) for drop
dup fgets eof? if drop exitfor else print endif
endfor
fclose
 
 
"input.txt" "r" fopen
eof? not while
dup fgets eof? if drop false else print true endif
endwhile
fclose</syntaxhighlight>
 
=={{header|PHP}}==
Line 2,998 ⟶ 3,044:
Loop
End Sub</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Zig">
import os
fn main() {
mut ay_view_content := []string{}
file := "./input.txt"
// check if file exists
if os.is_file(file) == false {
print("Error: '${file}' not found")
exit(-1)
}
ay_view_content << os.read_lines(file) or {print(err) exit(-2)}
for line in ay_view_content {
if line !="" {println(line)}
if line =="" {println("Found blank line!")}
}
}
</syntaxhighlight>
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
File.open("input.txt") { |file|
Anonymous user