Computer Programming
Computer Programming
Computer Languages
Machine Language
-Uses binary code
-Machinedependent
-Not portable
Assembly Language Dynamically Type
-symbolic representation of the machine -checked at run-time.
language of a specific processor.
-converted to machine code by an *Type Safety: Safe or Unsafe
assembler. -degree to which a language will prohibit
-Each line of assembly code produces one operations on typed variables that might
machine instruction (One-to-one lead to undefined behavior or errors.
correspondence). Safe Language
-Programming in assembly language is -will do more to ensure that such
slow and error-prone but is more efficient operations or conversions do not occur.
in terms of hardware performance. Unsafe Language
- A Mnemonic representation of the -will give more responsibility to the user in
instructions and data. this regard.
Start of a Program
- Marks the beginning of the DISADVANTAGES OF Pseudocode
program.
Does notv provide a visual
Statement Block representation of a logic
-statement to execute or behaviour programming.
to perform. No proper format for writing the
pseudocode.
Decision Block There is extra need to maintain
-decision point in program. documentation.
-ask a simple question, and do There is no proper standard.
different things depending on the
answer. WRITING a Pseudocode
Step 1:
Yes/No (True or False, etc.) Arrange the sequence of tasks and
-Answers to the question posed in write the pseudocode accordingly.
the decision block.
Step 2:
End Program Start with the statement of a
-Marks the end of the program. pseudocode which establishes the
main goal or aim.
GUIDELINES for developing Flowchart
Can only have one start and stop Pseudocode COMPONENTS
symbol.
On-page connectors are referenced Repitition
using numbers. Variables
Off-page connector are referenced Input-Output
using alphabets. Selection
General flow of processes is stop to Assignment
bottom or left to right.
Arrows should not cross each other.
Checking of Counter:
Selection(Decision) Counter Not Reached: counter
-decision-making structure has not reached the desired
-process of deciding which choice is made numbers, the next instruction in
between two or more alternative courses of the sequence returns to the first
action. instruction in the sequence and
If-then-else repeat it.
Case Construct Counter Reached: If the
-indicates a multiway branch condition has been reached, the
based on the conditions that are next instruction “falls through” to
mutually exclusive(Case, Of, the next sequential instruction or
Others, and Endcase) branches outside the loop.
Iteration or Repetition(Looping)
2 categories of loops:
-three fields in a for-loop are optional.
Entry Controlled Loops -can be left empty, but in all cases the
-The test condition is at the top. semicolon between of them are required.
-While loop, for loop.
Example :
Exit Controlled Loop For(;n<10;)
-test condition is at the bottom. --without initialization or increase (while-
loop)
3 statements of Loop:
Initialization expression For(;n<10;++n)
Test expression --with increase, but no initialization (maybe
Update expression because the variable was already initialized
before the loop).
While loop
Syntax: -No condition (INFINITE LOOP)
initialization expression; --loop with true as condition.
while(test expression)
{ Infinite Loop
//statements -if the condition is always TRUE—infinite
update_expression; times.
} Syntax:
For Loop //infinite while loop
Syntax:
for(initialization expression;condition; While(true){
update_expression){
//body of loop //body of the loop
}
}
Initialization
-initializes variables and is executed only IMPORTANT POINTS
once. Use for loop
Condition -when number of iteration is known
-if true—executed. beforehand.
-if false—terminated.
Update Use while loops
-updates the value of initialized variables -where exact number of iterations is
and again checks the condition. not known but the loop termination
condition is known.
PROCESS-for Loop
Use do while loop
1. Initialization is executed.(only at the -if the code needs to be executed at
beginning of the loop) least once like MENU driven
2. Condition is checked.(if true— programs.
continues. If false—end. Will be
skipped and jump to step 5) Jump Statement
3. Statement is executed.(single -allow altering the flow of a program by
statement or enclosed in curly performing jumps to specific locations.
braces) -used to alter the flow of control
4. Increase is executed, and the loop unconditionally.
gets back to step 2. -Transfer the program control within a
5. The loop execution continues by the function unconditionally.
next statement after it. -used standard library function exit()
To jump out the entire program.
TIPS-for Loop
Jump Statement BREAK STATEMENT
Break -used when we are not sure about
-used to terminate the loop. the actual number of iterations for
the loop or we want to terminate the
Continue loop base on the some condition.
-used to execute other parts of the
loop while skipping some parts CONTINUE STATEMENT
declared inside the condition, rather -used to skip the current iteration of
that terminating the loop, it the loop and the control of the
continues to execute the next program goes to the next iteration.
iteration of the same loop.
GOTO STATEMENT
Goto -jump statement and sometimes
-unconditional jump. referred to unconditional jump
-used to jump anywhere within a statement.
function.
- used to jump anywhere within a
Return function.
-stronger than break.
Used to terminate the entire function EXIT()
after the execution of the function of -terminates the calling process
after some condition. without executing the rest code
which is after exit() function.
Exit() statement
Syntax: exit(); RETURN STATEMENTS
-returns the flow of execution to the
-standard lib function that terminate the function from where it’s called.
entire program immediately and passes the
control to the operating system.
Return Statement
Syntax: return expression(opt);
IMPORTANT POINTS