Pascal - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Pascal Code Flow

Pascal Code Flow

shape Description

Making a decision in order to execute a group of statements meeting the given conditions or repeat the execution until the conditions are satisfied is called as Decision Making. The control statements are makes the developer to change the flow of code execution that altering the normal program flow to jump directly on some statement. The following are the decision making statements.

The If Statement

shape Description

If statement is used to return the true value, following is the conceptual figure which can guide simply. In the following figure if condition is true then it goes for action otherwise it checks for the alternative action finally code will be closed. The following is an example, where a is the integer type with the value 100 and by using if statement conditon will be as follows. [c]program ifstatement; var { local variable declaration } a:integer; begin a:= 100; (* check the boolean condition using if statement *) if( a < 200 ) then (* if condition is true then print the following *) writeln('a is less than 20 ' ); writeln('value of a is : ', a); end.[/c] Output: In the above example the value of a is less than 200 so the if statement will get execute. Now the result will be as follows. [c]a is less than 20 value of a is : 10[/c]

If-Else Statement

The functionality of If-Else statement is to return else result in case if result is false. The following is an example. [c] program ifelsestatement; var { local variable definition } a : integer; begin a := 80; (* check the boolean condition *) if( a < 50 ) then (* if condition is true then print the following *) writeln('a is less than 50' ) else (* if condition is false then print the following *) writeln('a is not less than 50' ); writeln('value of a is : ', a); end.[/c] Output: Now compile the code result will be as follows. [c]a is not less than 50 value of a is : 80[/c]

Case Statement

shape Description

The case statement is executes one statement from multiple conditions. Following is the conceptual figure to under stand the case statement concept. In the following figure compiler checks the every condition if it is true prints the statement otherwise checks the case until find the solution. The following is an example. [c]program checkCase; var grade: char; begin grade := 'B'; case (grade) of 'A' : writeln('Excellent!' ); 'B', 'C': writeln('Well done' ); 'D' : writeln('You passed' ); 'F' : writeln('Better try again' ); end; writeln('Hei, Your grade is ', grade ); end.[/c] Output:Now compile the code result will be as follows. [c] Well done Hei, Your grade is B[/c]

Summary

shape Key Points

  • Decision making statements are same in all the languages such as C, Java.
  • One case statement may have multiple case statements.
  • The compiler will take care about case expression matching.