If you need more than one statement in then part of the if, you would write: if x<0 then begin x : -x y : 3 end. This is again one statement (if) which have one statement after then (which consists of two statements). For example: if x<0 then x : -x is one statement. I am trying to figure out the correct way of passing an example that was using Free Pascal case statements to a simple if statement. If the boolean expression condition evaluates to true, then the if-then block of code will be executed, otherwise the else block of code will be executed. If you need more than one statement in then part of the if, you would write: if x<0 then begin x : -x y : 3 end. Checking to see if a number is within a range in free pascal. No semicolon ( ) is given before the last else keyword, but all statements can be compound statements. For example: if x<0 then x : -x is one statement. Once an else if succeeds, none of the remaining else if's or else's will be tested. Quantificator a mustnt be zero') 2: writeln (output, 'Double root of the equation is: x1x2',x1) 3: writeln (output, 'Roots of the equation are x1',x1,'and x2',x2,'.') 4: writeln (output, 'Complex roots of the equation are x1',R1,'+i',I1,' and x2',R2,'+i',I2,'.') end end. When using if-then, else if-then, else statements there are few points to keep in mind.Īn if-then statement can have zero or one else's and it must come after any else if's.Īn if-then statement can have zero to many else if's and they must come before the else. When the above code is compiled and executed, it produces the following result −Īn if-then statement can be followed by an optional else if-then-else statement, which is very useful to test various conditions using single if-then-else if statement. (* if condition is false then print the following *) While the same semantics can be achieved by consecutive if-then-branches, utilizing a case-statement allows the code generator to optimize the branch selection. Instead of writing else the word otherwise is allowed, too. (* if condition is true then print the following *) Note, case-statements accept expressions as selector.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |