Forum > Beginners

why skip read in for loop

(1/2) > >>

NoReason:
program Project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };
  var
    a:string;
    b1:string;
    b:array [1..100] of string;
    i,c:integer;

begin
  writeln('Upisi ime programa');
  read(a);
  writeln('koliko reci posle imena programa zelis da imas?');
  read(c);

  for i:=1 to c do
  begin
    writeln('Upisi ',i,' rec');
    read(b[i ]); (this)
   

  end;
  writeln;
  writeln('Ime programa je:',a);
  writeln;
  writeln('Niz reci posle imena programa su:');
  for i:=1 to c do
  begin
    writeln(b[i ]);

  end;


   read(c);

end.
     

jamie:
For strings "READ" will return immediately if there are no Keys in the keyboard buffer or,  it will return
with only what was in the buffer before you called "READ"

"ReadLn" will wait for you to enter some data.

NoReason:
Thanks, but got another problem... How to compare 2 strings by ASCII? CompareText or CompareStr wont work :/

taazz:

--- Quote from: NoReason on November 28, 2017, 07:26:18 am ---Thanks, but got another problem... How to compare 2 strings by ASCII? CompareText or CompareStr wont work :/

--- End quote ---
They work as expected. At least I get proper results out of them provide a small sample which demonstrate your problem.


--- Quote from: jamie on November 28, 2017, 04:09:24 am ---For strings "READ" will return immediately if there are no Keys in the keyboard buffer or,  it will return
with only what was in the buffer before you called "READ"

"ReadLn" will wait for you to enter some data.


--- End quote ---
No sorry its the other way around. read will pause the program execution until there is something to read from the keyboard buffer.

NoReason:
When i Use Comparetext got "project1.lpr(37,6) Error: Identifier not found "CompareText"

But i found that i can write too like a>b (both strings) and this will give me true or not, so its practically same.

Navigation

[0] Message Index

[#] Next page

Go to full version