Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.1.0 - English


input

prompts the user for keyboard input

Syntax

x = input(message)
x = input(message, "string")

Arguments

message

character string: the inline prompting message. Extended UTF-8 characters are supported.

"string"

optional flag, to return the input as is, as a literal string in x.

x

  • without "string": x = evstr(keyboard_input)
  • With "string": x = keyboard_input

Description

x = input(message)

  • prints the message on a new line;
  • sets the caret at the message's end;
  • waits for a direct literal keyboard_input of any length, + enter. keyboard_input must be a valid Scilab expression provided on the current line, without continuation mark ... keyboard_input can include extended UTF-8 characters.
  • tries to evaluate x = evstr(k_input) :
    • If it succeeds, x is output.
    • Otherwise: an error is displayed, and the user is prompted again until a valid Scilab expression is entered.
If keyboard_input is empty or made of blanks, x is set to [].

x = input(message, "string") always sets x to the literal keyboard_input considered as a string, possibly empty "".

Examples

maxIter = input("Max number of iterations: ") // enter 300

δ = 1e-6;
tol = input("Tolerance: ")   // enter nothing or blanks

tol = input("Tolerance: ")   // enter 7*δ

f = input("Function: ");     // enter sin
f == sin
f(5)

s = "ABC";
r = input("Expression: ")    // enter s + "D"

res = input("Invalid expression: ")  // enter  s/4
--> maxIter = input("Max number of iterations: ") // enter 300
Max number of iterations: 300
 maxIter  =
   300.

--> δ = 1e-6;
--> tol = input("Tolerance: ")   // | = caret before enter
Tolerance:     |
 tol  =
    []

--> tol = input("Tolerance: ")   // enter 7*δ
Tolerance: 7*δ
 tol  =
   0.000007

--> f = input("Function: ");     // enter sin
Function: sin
--> f == sin
 ans  =
  T
--> f(5)
 ans  =
  -0.9589243

--> s = "ABC";
--> r = input("Expression: ")    // enter s + "D"
Expression: s + "D"
 r  =
  "ABCD"

--> res = input("Invalid expression: ")  // enter  s/4
Invalid expression: s / 4
Undefined operation for the given operands.
check or define function %c_r_s for overloading.

Invalid expression:

The "string" option returns the input string as is, with leading and trailing white spaces. Extended characters are accepted:

x = input("Prénom (surname): ","string")      //  enter André
--> x = input("Prénom (surname): ","string")  // | = caret before enter
Prénom (surname):   André   |
 x  =
  "  André   "

See also

  • x_dialog — Dialog for interactive multi-lines input.
  • x_mdialog — Dialog for interactive vector/matrix input.
  • x_choose — interactive window choice (modal dialog)
  • x_choices — interactive Xwindow choices through toggle buttons
  • x_matrix — Edits a matrix and waits for validation (modal)
  • evstr — evaluates Scilab expressions and concatenates their results

History

VersionDescription
6.0.0

In case where nothing is entered with the "string" option, input returns an empty string instead of a space.

Report an issue
<< diary Console lines >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon May 22 12:37:12 CEST 2023