| | |
May I ask you a question on Delphi?
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 93
Reputation:
Solved Threads: 0
Code a decision using an IF, THEN, ELSE statement (2 branch decision)
Code a one branch decision using a null else statement
The following is my answer:
Could you tell me why at the Line 22 & 25, we do not want to put full-stop / semi-colon after the 'end'? It makes me very confused about the punctuation marks.
Code a one branch decision using a null else statement
The following is my answer:
Pascal and Delphi Syntax (Toggle Plain Text)
program Negatives; {$APPTYPE CONSOLE} uses SysUtils, ourcrt; var balance, posNeg:integer; begin randomize; writeln ('Generating your bank balance'); writeln ('Please wait .....'); sleep (2000); //create a random number between 0 and 1000 balance:=random(1000); //randomly decide if the balance is negative //1 for positive, 0 for negative posNeg:=random(2); if posNeg=0 then begin balance:=balance*-1; writeln('Can you hear that sound? Its your cheque bouncing'); sound(200,1000); end else begin writeln ('Positive balance'); end; writeln('Your balance is ', balance); sleep(5000); end.
Could you tell me why at the Line 22 & 25, we do not want to put full-stop / semi-colon after the 'end'? It makes me very confused about the punctuation marks.
your code is working well,where is the problem?????
you can write here too:
if posNeg=0 then
begin
balance:=balance*-1;
writeln('Can you hear that sound? Its your cheque bouncing');
sound(200,1000);
end;
If NegPos = 1 Then writeln ('Positive balance');
In your example if you put a semicolon; after your If statement's end,then the compiler thinks that it is a short version of the if statement,and send you an error about the else part,try it.....';' Not allowed before 'ELSE'....now you got it?.....
you can write here too:
if posNeg=0 then
begin
balance:=balance*-1;
writeln('Can you hear that sound? Its your cheque bouncing');
sound(200,1000);
end;
If NegPos = 1 Then writeln ('Positive balance');
In your example if you put a semicolon; after your If statement's end,then the compiler thinks that it is a short version of the if statement,and send you an error about the else part,try it.....';' Not allowed before 'ELSE'....now you got it?.....
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
•
•
Join Date: Feb 2009
Posts: 93
Reputation:
Solved Threads: 0
I have got a problem on the punctuation mark and what is the meaning of the following code?
Pascal and Delphi Syntax (Toggle Plain Text)
posNeg:=random(2); if posNeg=0 then
Hi turbomen 
PosNeg is a variable,the Random() function generate a random number it will one or zero,and PosNeg's value willl be one of them,the If statement will evaluate the condition.The evaluating result can be only two values,such as [True] or the another is [False].
If true that posneg's value is zero Then,the program does the added commands,if the condition is FALSE then the [Else] branch follows if there is any....
Good practice,try it...
Load your code into delphi,press the [Run] menu and press [Trace Into F7],so you can go inside the program,by pressing the [F7] button,you will see the steps one by one,look at your If statement's changes with your own eyes...

PosNeg is a variable,the Random() function generate a random number it will one or zero,and PosNeg's value willl be one of them,the If statement will evaluate the condition.The evaluating result can be only two values,such as [True] or the another is [False].
If true that posneg's value is zero Then,the program does the added commands,if the condition is FALSE then the [Else] branch follows if there is any....
Good practice,try it...
Load your code into delphi,press the [Run] menu and press [Trace Into F7],so you can go inside the program,by pressing the [F7] button,you will see the steps one by one,look at your If statement's changes with your own eyes...
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
![]() |
Similar Threads
- Probably a silly question.. but im new to delphi :) (Pascal and Delphi)
- Binary constants??? (Pascal and Delphi)
- Delphi Remembering Help Question. (Pascal and Delphi)
- Delphi Unicode/RTF Question (Pascal and Delphi)
- Unresolved External Symbol Error (C++)
- Amount of virtual memory available? (Pascal and Delphi)
- Gettig delphi to wait for a button press before continuing (Pascal and Delphi)
- Delphi forum (Pascal and Delphi)
- Email crawler Software (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: generate sine waves with delphi
- Next Thread: Could you tell me what's wrong of my answer?
| Thread Tools | Search this Thread |





