Input loop: Difference between revisions

m
(added Arturo)
imported>Arakov
 
(5 intermediate revisions by 4 users not shown)
Line 1,290:
 
=={{header|Elena}}==
ELENA 46.x:
 
Using ReaderEnumerator
Line 1,299:
public program()
{
ReaderEnumerator.new(File.assign:("file.txt")).forEach(printingLn)
}</syntaxhighlight>
Using loop statement
Line 1,306:
public program()
{
using(var reader := File.assign:("file.txt").textreader())
{
while (reader.Available)
Line 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,655 ⟶ 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 3,025 ⟶ 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