BASIC SYNTAX ALGORITHM FLOW CHART Prasanna R Kovath Assistant Professor Department of Biotechnology St. Mary's College Thrissur
• Syntax refers to the rules that define the structure of a language. Syntax in computer programming means the rules that control the structure of the symbols, punctuation, and words of a programming language. • If the syntax of a language is not followed, the code will not be understood by a compiler or interpreter. • Basic syntax represents the fundamental rules of a programming language. Without these rules, it is impossible to write functioning code.
Why Is Syntax Important in Programming? • Syntax improves code readability. It ensures that the four C’s of coding are maintained: • Communication • Code integration • Consistency • Clarity
TYPICAL BASIC KEYWORDS • LET Introduces the assignment statement, and is required PRINT Provides free-form output END Is required • READ Assigns values to variables from internal data DATA Introduces internal data • GOTO Does just that, transfers to another line-numbered statement IF Gives a conditional GOTO • FOR Introduces the looping construct NEXT Terminates the looping construct • GOSUB Does a GOTO to a subroutine RETURN Returns from the end of the subroutine • DEF Introduces programmer-defined functions DIM Allows dimensioning arrays REM Provides comments STOP Same as reaching the END statement
• IF ... THEN ... ELSE: used to perform comparisons or make decisions. • FOR ... TO ... {STEP} ... NEXT: repeat a section of code a given number of times. • A variable that acts as a counter is available within the loop. WHILE ... WEND and REPEAT ... • UNTIL: repeat a section of code while the specified condition is true. The condition may be evaluated before each iteration of the loop, or after. • DO ... LOOP {WHILE} or {UNTIL}: repeat a section of code Forever or While/Until the specified condition is true . The condition may be evaluated before each iteration of the loop, or after. • GOTO: jumps to a numbered or labelled line in the program. PROGRAM FLOW CONTROL
• GOSUB: jumps to a numbered or labelled line, executes the code it finds there, • but upon encountering the RETURN Command, it jumps back to the line following the line from which the jump occurred. This is used to implement subroutines. • ON ... GOTO/GOSUB: chooses where to jump based on the specified conditions. See Switch statement for other forms. • DEF FN: a pair of keywords introduced in the early 1960s to define functions.
• I/O: Input and Output • PRINT: displays a message on the screen or other output device. • INPUT: asks the user to enter the value of a variable. The statement may include a prompt message. • TAB or AT: sets the position where the next character will be shown on the screen or printed on paper • The PRINT statement allows several quantities, including quoted strings, separated by commas (,) or semicolons (;).
MISCELLANEOUS SYNTAX • REM: holds a programmer's comment or REMark; often used to give a title to the program and to help identify the purpose of a given section of code. • USR: transfers program control to a machine language subroutine, usually entered as an alphanumeric string or in a list of DATA statements. • TRON: turns on a visual, screen representation of the flow of BASIC commands by displaying the number of each command line as it is run. The TRON command, largely obsolete now, stood for, TRace ON. • This meant that command line numbers were displayed as the program ran, so that the command lines could be traced. This command allowed easier debugging or correcting of command lines that caused problems in a program. • Miscellaneous Syntax Problems included a program terminating without providing a desired result
ARITHMETIC OPERATIONS • Arithmetic operators are used to carry out arithmetic operations in BASIC. These operators are executed according to their hierarchy or what is called precedence rule.
• The hierarchy determines the sequence Basic follows in executing a group of arithmetic operators found in an arithmetic expression. • The operation with the highest hierarchy is executed first and the one with operators; this can be altered during execution by introducing parenthesis (i.e. a pair of brackets) in the appropriate place(s) in expression. • The content of the bracket will be evaluated first. • This overriding rule is applicable to all other arithmetic operators as well. Multiplication and division come next to exponentiation in hierarchy with multiplication not necessarily preceding division. • Addition and subtraction comes last in the hierarchy of arithmetic operators with addition not necessarily preceding subtraction in execution.
RELATIONAL OPERATIONS IN BASIC
LOGICAL OPERATIONS IN BASIC • Logical operations in BASIC involve use of logical operators NOT. AND OR which must yield logical values TRUE (T) or FALSE (F).
What Is Algorithm? Algorithm Basics • The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
What are the Characteristics of an Algorithm?
• Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning. • Well-Defined Inputs: If an algorithm says to take inputs, it should be well- defined inputs. • Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well. • Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite loops or similar. • Feasible: The algorithm must be simple, generic and practical, such that it can be executed upon will the available resources. It must not contain some future technology, or anything. • Language Independent: The Algorithm designed must be language- independent, i.e. it must be just plain instructions that can be implemented in any language, and yet the output will be same, as expected.
Advantages of Algorithms: • It is easy to understand. • Algorithm is a step-wise representation of a solution to a given problem. • In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program. Disadvantages of Algorithms: • Writing an algorithm takes a long time so it is time-consuming. • Branching and Looping statements are difficult to show in Algorithms.
How to Design an Algorithm? • In order to write an algorithm, following things are needed as a pre- requisite: • The problem that is to be solved by this algorithm. • The constraints of the problem that must be considered while solving the problem. • The input to be taken to solve the problem. • The output to be expected when the problem the is solved. • The solution to this problem, in the given constraints.
• Example: Consider the example to add three numbers and print the sum. • Step 1: Fulfilling the pre-requisites As discussed above, in order to write an algorithm, its pre-requisites must be fulfilled. • The problem that is to be solved by this algorithm: Add 3 numbers and print their sum. • The constraints of the problem that must be considered while solving the problem: The numbers must contain only digits and no other characters. • The input to be taken to solve the problem: The three numbers to be added. • The output to be expected when the problem the is solved: The sum of the three numbers taken as the input. • The solution to this problem, in the given constraints: The solution consists of adding the 3 numbers. It can be done with the help of ‘+’ operator, or bit-wise, or any other method.
• Step 2: Designing the algorithm Now let’s design the algorithm with the help of above pre- requisites: Algorithm to add 3 numbers and print their sum: • START • Declare 3 integer variables num1, num2 and num3. • Take the three numbers, to be added, as inputs in variables num1, num2, and num3 respectively. • Declare an integer variable sum to store the resultant sum of the 3 numbers. • Add the 3 numbers and store the result in the variable sum. • Print the value of variable sum • END • Step 3: Testing the algorithm by implementing it.
FLOWCHARTS • What is a Flowchart? Flowchart is a graphical representation of an algorithm. Programmers often use it as a program-planning tool to solve a problem. It makes use of symbols which are connected among them to indicate the flow of information and processing. The process of drawing a flowchart for an algorithm is known as “flowcharting”.
BASIC SYMBOLS USED IN FLOWCHART DESIGNS • Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow. A pause/halt is generally used in a program logic under some error conditions. Terminal is the first and last symbols in the flowchart. • Input/Output: A parallelogram denotes any function of input/output type. Program instructions that take input from input devices and display output on output devices are indicated with parallelogram in a flowchart.
• Processing: A box represents arithmetic instructions. All arithmetic processes such as adding, subtracting, multiplication and division are indicated by action or process symbol. • Decision Diamond symbol represents a decision point. Decision based operations such as yes/no question or true/false are indicated by diamond in flowchart. • Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use connectors to avoid any confusions. It is represented by a circle. • Flow lines: Flow lines indicate the exact sequence in which instructions are executed. Arrows represent the direction of flow of control and relationship among different symbols of flowchart.
ADVANTAGES OF FLOWCHART • Flowcharts are better way of communicating the logic of system. • Flowcharts act as a guide for blueprint during program designed. • Flowcharts helps in debugging process. • With the help of flowcharts programs can be easily analyzed. • It provides better documentation. • Flowcharts serve as a good proper documentation.
DISADVANTAGES OF FLOWCHART • It is difficult to draw flowchart for large and complex programs. • In this their is no standard to determine the amount of detail. • Difficult to reproduce the flowcharts. • It is very difficult to modify the Flowchart.
Larger of two numbers Adding three numbers
Largest of three numbers Sum of first N natural numbers

Basic syntax : Algorithm,Flow chart

  • 1.
    BASIC SYNTAX ALGORITHM FLOW CHART PrasannaR Kovath Assistant Professor Department of Biotechnology St. Mary's College Thrissur
  • 2.
    • Syntax refersto the rules that define the structure of a language. Syntax in computer programming means the rules that control the structure of the symbols, punctuation, and words of a programming language. • If the syntax of a language is not followed, the code will not be understood by a compiler or interpreter. • Basic syntax represents the fundamental rules of a programming language. Without these rules, it is impossible to write functioning code.
  • 3.
    Why Is SyntaxImportant in Programming? • Syntax improves code readability. It ensures that the four C’s of coding are maintained: • Communication • Code integration • Consistency • Clarity
  • 4.
    TYPICAL BASIC KEYWORDS •LET Introduces the assignment statement, and is required PRINT Provides free-form output END Is required • READ Assigns values to variables from internal data DATA Introduces internal data • GOTO Does just that, transfers to another line-numbered statement IF Gives a conditional GOTO • FOR Introduces the looping construct NEXT Terminates the looping construct • GOSUB Does a GOTO to a subroutine RETURN Returns from the end of the subroutine • DEF Introduces programmer-defined functions DIM Allows dimensioning arrays REM Provides comments STOP Same as reaching the END statement
  • 5.
    • IF ...THEN ... ELSE: used to perform comparisons or make decisions. • FOR ... TO ... {STEP} ... NEXT: repeat a section of code a given number of times. • A variable that acts as a counter is available within the loop. WHILE ... WEND and REPEAT ... • UNTIL: repeat a section of code while the specified condition is true. The condition may be evaluated before each iteration of the loop, or after. • DO ... LOOP {WHILE} or {UNTIL}: repeat a section of code Forever or While/Until the specified condition is true . The condition may be evaluated before each iteration of the loop, or after. • GOTO: jumps to a numbered or labelled line in the program. PROGRAM FLOW CONTROL
  • 6.
    • GOSUB: jumpsto a numbered or labelled line, executes the code it finds there, • but upon encountering the RETURN Command, it jumps back to the line following the line from which the jump occurred. This is used to implement subroutines. • ON ... GOTO/GOSUB: chooses where to jump based on the specified conditions. See Switch statement for other forms. • DEF FN: a pair of keywords introduced in the early 1960s to define functions.
  • 7.
    • I/O: Inputand Output • PRINT: displays a message on the screen or other output device. • INPUT: asks the user to enter the value of a variable. The statement may include a prompt message. • TAB or AT: sets the position where the next character will be shown on the screen or printed on paper • The PRINT statement allows several quantities, including quoted strings, separated by commas (,) or semicolons (;).
  • 8.
    MISCELLANEOUS SYNTAX • REM:holds a programmer's comment or REMark; often used to give a title to the program and to help identify the purpose of a given section of code. • USR: transfers program control to a machine language subroutine, usually entered as an alphanumeric string or in a list of DATA statements. • TRON: turns on a visual, screen representation of the flow of BASIC commands by displaying the number of each command line as it is run. The TRON command, largely obsolete now, stood for, TRace ON. • This meant that command line numbers were displayed as the program ran, so that the command lines could be traced. This command allowed easier debugging or correcting of command lines that caused problems in a program. • Miscellaneous Syntax Problems included a program terminating without providing a desired result
  • 9.
    ARITHMETIC OPERATIONS • Arithmeticoperators are used to carry out arithmetic operations in BASIC. These operators are executed according to their hierarchy or what is called precedence rule.
  • 10.
    • The hierarchydetermines the sequence Basic follows in executing a group of arithmetic operators found in an arithmetic expression. • The operation with the highest hierarchy is executed first and the one with operators; this can be altered during execution by introducing parenthesis (i.e. a pair of brackets) in the appropriate place(s) in expression. • The content of the bracket will be evaluated first. • This overriding rule is applicable to all other arithmetic operators as well. Multiplication and division come next to exponentiation in hierarchy with multiplication not necessarily preceding division. • Addition and subtraction comes last in the hierarchy of arithmetic operators with addition not necessarily preceding subtraction in execution.
  • 11.
  • 12.
    LOGICAL OPERATIONS INBASIC • Logical operations in BASIC involve use of logical operators NOT. AND OR which must yield logical values TRUE (T) or FALSE (F).
  • 16.
    What Is Algorithm?Algorithm Basics • The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
  • 17.
    What are theCharacteristics of an Algorithm?
  • 18.
    • Clear andUnambiguous: Algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning. • Well-Defined Inputs: If an algorithm says to take inputs, it should be well- defined inputs. • Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well. • Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite loops or similar. • Feasible: The algorithm must be simple, generic and practical, such that it can be executed upon will the available resources. It must not contain some future technology, or anything. • Language Independent: The Algorithm designed must be language- independent, i.e. it must be just plain instructions that can be implemented in any language, and yet the output will be same, as expected.
  • 19.
    Advantages of Algorithms: •It is easy to understand. • Algorithm is a step-wise representation of a solution to a given problem. • In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program. Disadvantages of Algorithms: • Writing an algorithm takes a long time so it is time-consuming. • Branching and Looping statements are difficult to show in Algorithms.
  • 20.
    How to Designan Algorithm? • In order to write an algorithm, following things are needed as a pre- requisite: • The problem that is to be solved by this algorithm. • The constraints of the problem that must be considered while solving the problem. • The input to be taken to solve the problem. • The output to be expected when the problem the is solved. • The solution to this problem, in the given constraints.
  • 21.
    • Example: Considerthe example to add three numbers and print the sum. • Step 1: Fulfilling the pre-requisites As discussed above, in order to write an algorithm, its pre-requisites must be fulfilled. • The problem that is to be solved by this algorithm: Add 3 numbers and print their sum. • The constraints of the problem that must be considered while solving the problem: The numbers must contain only digits and no other characters. • The input to be taken to solve the problem: The three numbers to be added. • The output to be expected when the problem the is solved: The sum of the three numbers taken as the input. • The solution to this problem, in the given constraints: The solution consists of adding the 3 numbers. It can be done with the help of ‘+’ operator, or bit-wise, or any other method.
  • 22.
    • Step 2:Designing the algorithm Now let’s design the algorithm with the help of above pre- requisites: Algorithm to add 3 numbers and print their sum: • START • Declare 3 integer variables num1, num2 and num3. • Take the three numbers, to be added, as inputs in variables num1, num2, and num3 respectively. • Declare an integer variable sum to store the resultant sum of the 3 numbers. • Add the 3 numbers and store the result in the variable sum. • Print the value of variable sum • END • Step 3: Testing the algorithm by implementing it.
  • 23.
    FLOWCHARTS • What isa Flowchart? Flowchart is a graphical representation of an algorithm. Programmers often use it as a program-planning tool to solve a problem. It makes use of symbols which are connected among them to indicate the flow of information and processing. The process of drawing a flowchart for an algorithm is known as “flowcharting”.
  • 25.
    BASIC SYMBOLS USEDIN FLOWCHART DESIGNS • Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow. A pause/halt is generally used in a program logic under some error conditions. Terminal is the first and last symbols in the flowchart. • Input/Output: A parallelogram denotes any function of input/output type. Program instructions that take input from input devices and display output on output devices are indicated with parallelogram in a flowchart.
  • 26.
    • Processing: Abox represents arithmetic instructions. All arithmetic processes such as adding, subtracting, multiplication and division are indicated by action or process symbol. • Decision Diamond symbol represents a decision point. Decision based operations such as yes/no question or true/false are indicated by diamond in flowchart. • Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use connectors to avoid any confusions. It is represented by a circle. • Flow lines: Flow lines indicate the exact sequence in which instructions are executed. Arrows represent the direction of flow of control and relationship among different symbols of flowchart.
  • 27.
    ADVANTAGES OF FLOWCHART •Flowcharts are better way of communicating the logic of system. • Flowcharts act as a guide for blueprint during program designed. • Flowcharts helps in debugging process. • With the help of flowcharts programs can be easily analyzed. • It provides better documentation. • Flowcharts serve as a good proper documentation.
  • 28.
    DISADVANTAGES OF FLOWCHART •It is difficult to draw flowchart for large and complex programs. • In this their is no standard to determine the amount of detail. • Difficult to reproduce the flowcharts. • It is very difficult to modify the Flowchart.
  • 29.
    Larger of twonumbers Adding three numbers
  • 30.
    Largest of threenumbers Sum of first N natural numbers