70 likes | 203 Views
Input and Output (2). Input Statement. Input Statement. Read user input from the keyboard Then assign the value read to a variable There are two input statements in Pascal read readln. readln statement. Syntax: readln ( <input list> )
E N D
Input and Output (2) Input Statement
Input Statement • Read user input from the keyboard • Then assign the value read to a variable • There are two input statements in Pascal • read • readln
readln statement • Syntax: • readln ( <input list> ) • <input list> could be a single variable or a list of variables separated by commas • All entries in the <input list> must be variable • Input data is read after the user press Enter key
readln statement (cont.) • Example • var Num1, Num2 : integer; • readln ( Num1 ); • readln ( Num2 ); • writeln ( ‘The numbers are ‘, Num1, ‘, ‘, Num2); 5 8 The numbers are 5, 8
Read more than one variable • To read more than one variable in the same row, put more than one variable in the <input list> in the readln statement and separate these variables with commas • Keyboard inputs are separated by blank space, tab or new line
Read more than one variable • If the number of input values is more than the number of variables in <input list>, excess values are ignored • If the number of input values is less than the number of variables in <input list> when user press Enter, it will wait for more input from user.