Tuesday, October 31, 2023

AKTU MCA I FCET UNIT I notes

 

Syllabus

Unit I

Introduction to Computer: Definition, Computer Hardware & Computer Software Components: Hardware – Introduction, Input devices, Output devices, Central Processing Unit, Memory- Primary and Secondary. Software - Introduction, Types – System and Application.

Computer Languages: Introduction, Concept of Compiler, Interpreter &Assembler

Problem solving concept: Algorithms – Introduction, Definition, Characteristics,

Limitations, Conditions in pseudo-code, Loops in pseudo code.

 

*************************************************************************************

UNIT I

----------

COMPUTER: AN INTRODUCTION

 

Like many other machines, a computer is also a system. Any system has three main components input-process-output. As our human body, we listen from our ear process it under our brain and when we find some result we can show the output with the help of mouth (speak) or hand (writing). No system can work independently. Like many other systems, computers are also a system, it takes command, instructions, raw data, etc. with the help of specified input devices and then processes it with a special device that is called a processor (processor work on preloaded program) and then produces a result. It can be understood with an example suppose that you want to find the result of 15 * 5 to do this you can take the help of a computer. The computer takes input (15 * 5) then the processor processes it on the basis of a table program that is preloaded and gets the result i.e. 75. But how could you know the result so there are some output devices which are used to show the result that is produced by the processor? In very short we can say that a computer is a system for data processing. A computer has a huge storage capacity. We can store millions of libraries on a single computer.  A computer can store any amount of information because of its secondary storage. Every piece of information can be stored as long as desired by the user and can be recalled when required. A byte is a storage unit. Normally 1 TB (TeraByte) hard disk is used in desktop. Later we will discuss these units in detail.                 

           

Definition:      we can define a computer in different perspectives like a Computer is a machine, a computer is an electronic device, a Computer is a data processor, and a computer is a digital device. Etc. but in a much-summarized way…

 

A computer is a digital device that takes data process it under some specific program and produces some meaningful output.

 

Mainly computer is a digital data problem solver or action performer. It takes data to process it on the basis of some previously loaded program (set of instructions) and produces the desired result. A computer can’t do anything that is not pre-loaded into it.

 

 

Characteristics of a computer

Speed        The speed of computers is very fast. It can perform in a few seconds the amount of work that human beings can do in an hour. When we are talking about the speed of a computer we do not talk in terms of seconds or even milliseconds it is nanoseconds. The computer can perform about 3 to 4 million arithmetic operations per second. The unit of speed of the computer is Hertz. A normal desktop computer processor speed is between 3.50 to 4.2 GHz.

 

 Accuracy       accuracy of computer is very high or in other word we can say that if program design is very good Computer cannot do any mistake. Basically, the accuracy of the program is depending on the accuracy of program writing. So after a long period of time on program testing and the debugging program becomes more accurate. The accuracy of a particular program becomes more accurate Day by day.

 

Alertness Computer is a machine so it does not get tired and hence can work for long time without creating any error or mistake. It means that there is no different to perform one arithmetic operation 10 arithmetic operation or for thousand or millions of arithmetic operations the result will be same because of there is no issue of tiredness like human beings. The computer always works on full alert mode.

 

 Versatility      Modern era demands versatility from everyone. In cricket, the all-rounder is more on the demand of the player. The same player has also liked if the batsman is also a bowler; he is also a good fielder. In the same way, people want to get more and more work from the same machine. Nowadays we can perform any task with the help of a computer. we can type, watch movies, listening songs, internet browse, download files, perform many government-related official jobs using e-governance and so many other useful tasks can be done using a single machine it is called versatility. A computer is capable of performing almost any task provided that the task can be reduced to a series of logical steps.

           A computer is a digital device that takes data process it under some specific program and produces some meaningful output.

 

        Mainly computer is a digital data problem solver or action performer. It takes data to process it on the basis of some previously loaded program (set of instructions) and produces the desired result. A computer can’t do anything that is not pre-loaded into it.

 

     

           Artificial Intelligence (AI):    Above characteristics belong to some traditional computer systems nowadays modern computers come with AI. It means that it can perform much better than previously loaded programs. An artificial intelligence inbuilt computer can take its own decision. Google search is based on artificial intelligence it produces the result of searching on the basis of a particular user searching experience. This type of computer can change the program it can modify the loaded program 

Elements of a Computer System set up:

There are mainly five elements of a computer system.

(i)         Hardware: the physical part of the computer system that we can see, touch, and move from one place to another is called hardware. For example mouse, keyboard, optical scanner, monitor, printer, processor, etc.

 

(ii)        Software: it is the part of the computer system that we cannot see but the whole system is based on that part, we call it software. Software is mainly a collection of programs. And the program is a set of instructions to solve any given problem or to perform any particular job. All the work of the computer depends on the program. The computer cannot do anything that is not already written in the program, that is, what the computer can do. Everything is already written in the program. Basically, there are two major classifications of software, namely System Software and Application Software.

 

System software: software that is for a computer system. A computer system consists of many parts so a different type of software is needed for each part. In other, we can say that system software is for hardware. A user can not directly interact with system software but without it, he cannot access the services of particular software. If said in very simple words, then it can be said that the system software acts as an intermediary between the hardware of the computer and the user who uses that computer.

For example, if we want to use a printer, then without printer software (sometimes it is called printer driver software), we cannot use it. With the help of printer software, the computer performs various functions of the printer. Sometimes it is also called device drivers.  ROM -BIOS driver, printer driver, USB drivers, motherboard drivers, VGA drivers are some examples of system software. Sometimes the operating system is also considered as system software.

Application software: Application software is the software that is made for a particular work. It is written for a particular application. It is also called end-user software. End-user means that the user interacts with. A computer user directly interacts with it .every application software is written for a particular work for example word processor software is made for only word processing, paintbrush software is made only for painting type of work, the internet browser is used for browsing the internet, etc.

Ms-office, ms-paint, Tux-paint, notepad, adobe reader, Mozilla Firefox, Google Chrome, calculator are some very common examples of application software.

 

(iii)Human being        the most important element of a computer system is its users.

The user's convenience is seen while designing the interface of any application software. We cannot imagine the computer world without human beings. The computer is made by humans and it is made for humans only. Humans cannot be separated from a computer element. Data analysis, computer programmer, server administrator, and computer operators are some important examples of this.

(iv) Data:          data is also a very important element of a computer system. Basically, a computer is a data processor so without data, a computer cannot perform anything. Any raw fact is called data and after processing this data becomes information. Suppose we have to find 799 whether it is an odd or even number, then we will call 799 as data, and the rule with which we will find out whether it is even or odd is called a program. And the result that will come out will be output. So both the result and the program depend on our data, so data is mandatory for computers. The same data can present many types of results; hence the demand for data analysis has also increased nowadays. Text, audio, images, and video are some most common forms of data. With the help of appropriate software word processing, image processing, audio processing, and video processing can be performed to get desired output.

(v) Network setup    it is not possible to imagine computers without the internet nowadays. Internet is a network of networks. it means that the internet is dependent on various kinds of networks. Most of the networks are belong to the Telecom network for example BSNL, Airtel, jio, etc. So it is very important for the Internet to have this kind of network. 

Components of a Computer System

There are basically three main components of a computer system. Input unit, Process unit, and Output unit. Our computer system is based on these three main components. If we talk about any element of the computer, then it will be related to any one of these three components. To understand the working of the computer, it is very important to understand how these three components are related, and to understand this; we can take the help of a block diagram.

 

 

           

 

Input unit:            The main function of this unit is to take data, commands or instructions. To receive data from the user or any other means input devices are used. Mouse, keyboard, joystick, scanner, are some most popular examples of input devices.

 


 

 

 

Process unit of C.P.U.(central processing unit ):   This is the core unit of a computer system. It is also called the brain of the computer. Basically, the main task of the computer is done by this unit. Because of this unit computer is called a data processor. In a very simple word, we can say that it is not a part of a computer but it is a computer. The job of this unit is very complicated so it consists of three parts CPU, memory, and storage.

CPU (central processing unit):     it is a combination of ALU (arithmetic and Logical unit) and CU (control unit).ALU performs arithmetic and logical operation such as addition; subtraction comparison etc. and CU perform control operation of the computer system.

 

Memory:     it is a helper of the CPU. As you know we cannot do anything without memory in the same way CPU also needed memory to store temporary data in the meanwhile of processing. It is used from taking data from input devices to show the result. Everywhere temporary memory is required. To do this RAM (Random Access Memory) is used along with the CPU. There is also a special type of memory is used that is call ROM (Read Only Memory).it holds data permanently. It is very costly so only the data that is required for opening the computer is stored in it. So it can be said that there are two types of computer memory RAM and ROM. always remember only RAM is called computer main memory.

There are two main types of computer memory: primary memory and secondary memory.

Primary memory is also known as main memory or internal memory. It is the memory that the CPU can access directly. Primary memory is volatile, meaning that data is lost when the power is turned off. The two main types of primary memory are:

  • Random access memory (RAM) is used to store data that the CPU is currently using. RAM is very fast, but it is also expensive.
  • Read-only memory (ROM) is used to store data that the computer needs to boot up and operate. ROM is non-volatile, meaning that data is retained even when the power is turned off.

Secondary memory is also known as external memory or auxiliary memory. It is used to store data that the CPU does not need to access immediately. Secondary memory is non-volatile and is typically much slower than primary memory. Some common types of secondary memory include:

  • Hard disk drives (HDDs) are the most common type of secondary memory. They are relatively slow, but they can store large amounts of data.
  • Solid-state drives (SSDs) are a newer type of secondary memory that is much faster than HDDs. SSDs use flash memory to store data, which is the same type of memory used in USB drives and SD cards.
  • Optical storage devices such as CDs, DVDs, and Blu-rays are used to store data that needs to be portable or archived.

In addition to primary and secondary memory, there are a few other types of memory that are used in computers:

  • Cache memory is a small amount of very fast memory that is used to store data that the CPU is likely to need soon. Cache memory is typically located between the CPU and primary memory.
  • Register memory is a small amount of memory that is built into the CPU. Register memory is used to store data that the CPU is currently working on.

The different types of computer memory are designed for different purposes. Primary memory is used to store data that the CPU needs to access immediately, while secondary memory is used to store data that the CPU does not need to access immediately. Cache memory is used to speed up access to data that the CPU is likely to need soon, while register memory is used to store data that the CPU is currently working on.

 


 

Difference between RAM and ROM

Difference

RAM

ROM

Data retention

RAM is a volatile memory that could store the data as long as the power is supplied.

ROM is a non-volatile memory that could retain the data even when power is turned off.

Working type

Data stored in RAM can be retrieved and altered.

Data stored in ROM can only be read.

Use

Used to store the data that has to be currently processed by CPU temporarily.

It stores the instructions required during bootstrap ( start )of the computer.

Speed

It is a high-speed memory.

It is much slower than the RAM.

CPU Interaction

The CPU can access the data stored on it.

The CPU can not access the data stored on it unless the data is stored in RAM.

Size and Capacity

Large size with higher capacity.

Small size with less capacity.

Used as/in

CPU Cache, Primary memory.

Firmware, Micro-controllers

Accessibility

The data stored is easily accessible

The data stored is not as easily accessible as in RAM

Cost

Costlier

cheaper than RAM.

Storage devices:   

Storage devices have evolved significantly over the years, from the early days of punched cards and magnetic tapes to the modern-day SSDs and cloud storage.

Punched cards: Punched cards were one of the earliest forms of data storage. They were used to store data for computers and other machines. Punched cards were made of cardboard and had holes punched in them to represent data.

 

Punched cards

Magnetic tapes: Magnetic tapes were another early form of data storage. They were used to store data for computers and other machines. Magnetic tapes were made of plastic or metal and had a magnetic coating. Data was stored on the magnetic tape by magnetizing and demagnetizing the coating.



 



Magnetic tapes



Hard disk drives (HDDs): HDDs are the most common type of secondary storage device today. They use a spinning platter coated in magnetic material to store data. Data is read and written to the platter by a read/write head.



Solid-state drives (SSDs): SSDs are a newer type of secondary storage device that is much faster than HDDs. SSDs use flash memory to store data, which is the same type of memory used in USB drives and SD cards.



Cloud storage: Cloud storage is a type of storage device that is hosted over the internet. It is convenient and accessible from anywhere, but it can be more expensive than traditional storage devices.



Evolution of storage devices

The evolution of storage devices has been driven by a number of factors, including:

·         The need for more storage capacity: As computers have become more powerful, the need for more storage capacity has increased.

·         The need for faster storage: As computers have become faster, the need for faster storage has increased.

·         The need for more portable storage: As people have become more mobile, the need for more portable storage has increased.

·         The need for more affordable storage: As the cost of computing has decreased, the cost of storage has also decreased.

Future of storage devices

The future of storage devices is likely to be shaped by a number of trends, including:

·         The continued growth of data: The amount of data being generated and stored is growing exponentially. This is driving the need for more storage capacity.

·         The rise of artificial intelligence (AI): AI is becoming increasingly important in a wide range of applications. AI applications require large amounts of data to train and operate. This is driving the need for faster and more efficient storage devices.

·         The growth of the cloud: Cloud storage is becoming increasingly popular. Cloud storage providers are developing new technologies to improve the performance and reliability of cloud storage.

 


CD/DVD

 

CDs and DVDs are optical disc storage formats that were very popular in the past, but have been largely replaced by digital storage formats such as SSDs and cloud storage.

CDs were first released in 1982 and could store up to 700 MB of data. DVDs were first released in 1996 and could store up to 4.7 GB of data. DVDs were later updated to support dual-layer discs, which could store up to 8.5 GB of data.

CDs and DVDs were used to store a variety of data, including music, movies, software, and video games. CDs were also used to distribute music and software online.

CDs and DVDs have a number of advantages over other storage formats. They are relatively inexpensive, durable, and portable. However, CDs and DVDs are also relatively slow and have limited storage capacity.

The evolution of digital storage formats has led to the decline of CDs and DVDs. Digital storage formats such as SSDs and cloud storage are faster, have more storage capacity, and are more convenient to use.

 

 

Output units generally user interact with the input units and output units. After performing very complex data processing job processor produce a result but it is in electronic form human being cannot understand it. So to convert results into human-readable form output devices are used. The main function of the output unit is to convert digital data into a human-understandable form. Monitor and printer are the two most common output devices. Monitor display the result in a soft form on-screen and the printer produce the result on paper in a hard form so sometimes soft copy and hard copy terms are used for monitor and printer respectively. Speaker is also an output device that is used to produce audio for listening.

 

 


Types of output devices

There are a wide variety of output devices available, each with its own advantages and disadvantages. Some common types of output devices include:

Monitors: Monitors are the most common type of output device. They display text, images, and videos to the user. Monitors are available in a variety of sizes and resolutions, and can be used for a variety of tasks, such as working on documents, watching movies, and playing games.

Printers: Printers print text and images onto paper. Printers are available in a variety of types, including laser printers, inkjet printers, and thermal printers. Laser printers are the fastest type of printer, but they are also the most expensive. Inkjet printers are less expensive than laser printers, but they are also slower and can be more expensive to operate in the long run. Thermal printers are the least expensive type of printer, but they are also the slowest and produce the lowest quality prints.

Speakers: Speakers reproduce sound from a computer. Speakers are available in a variety of sizes and configurations, and can be used for a variety of tasks, such as listening to music, watching movies, and playing games.

Plotters: Plotters create high-quality drawings and schematics. Plotters are typically used in engineering and design applications.

Other types of output devices

In addition to these common types of output devices, there are a number of other specialized output devices available, such as:

Digital signage: Digital signage displays are used to display digital content, such as text, images, and videos, in public places.

Projectors: Projectors project images and videos onto a screen. Projectors are typically used in conference rooms and classrooms.

Interactive whiteboards: Interactive whiteboards allow users to interact with a computer using a stylus or their finger. Interactive whiteboards are typically used in classrooms and businesses.

Virtual reality (VR) headsets: VR headsets allow users to experience a simulated environment.

Augmented reality (AR) headsets: AR headsets overlay digital information onto the real world.

Internet of Things (IoT) devices: IoT devices collect and transmit data to the cloud.

Artificial intelligence (AI) devices: AI devices process data and make decisions using machine learning algorithms.

 

 

Computer Generations

We can divide the generation of computers into five stages. The sequence of computer generation is as follows.

First Generation (1940-1956)

Vacuum tubes or thermionic valve machines are used in first-generation computers.

Punched card and the paper tape were used as an input device.

For output printouts were used.

ENIAC (Electronic Numerical Integrator and Computer) was the first electronic computer is introduced in this generation.

Second Generation (1956-1963)

 Transistor technologies were used in this generation in place of the vacuum tubes.

Second-generation computers have become much smaller than the first generation.

Computation speed of second-generation computers was much faster than the first  generation so it takes lesser time to produce results.

 Third Generation (1963-1971)

Third generation of computers is based on Integrated Circuit (IC) technology.

 

Third generation computers became much smaller in size than the first and second generation, and their computation power increased dramatically.

 

The third generation computer needs less power and also generated less heat.

 

The maintenance cost of the computers in the third generation was also low.

 

Commercialization of computers was also started in this generation.

Fourth Generation (1972-2010)

The invention of microprocessor technology laid the foundation for the fourth generation computer.

Fourth generation computers not only became very small in size, but their ability to calculate also increased greatly and at the same time they became portable, that is, it became very easy to move them from one place to another.

The computers of fourth-generation started generating a very low amount of heat.

It is much faster and accuracy became more reliable because of microprocessor technology.

Their prices have also come down considerably.

Commercialization of computers has become very fast and it is very easily available for common people.

Fifth Generation (2010- till date)

AI (Artificial intelligence) is the backbone technology of this generation of computers. AI-enabled computers or programs behave like an intelligent person that’s why this technology is called artificial intelligence technology.

 In addition to intelligence, the speed of computers has also increased significantly and the size has also reduced much earlier than even the computer on the palm has been used.

Some of the other popular advanced technologies of the fifth generation include Quantum computation, Nanotechnology, Parallel processing, Big Data, and IoT, etc.

Computer language

A computer cannot understand our language because it is a machine. So, it understands machine language or we can say that the main language of computers is machine language. Now the question arises that which language a machine understands? The answer is very easy; it understands the language of on and off.

But due to the complexity of the work of computers nowadays, it is not easy to work with the computer only in the language of on and off, so some other languages are used for the computer.

Therefore, the language of computers is mainly divided into three parts.

1.            Machine language: - Machine language is the language in which only 0 and 1 two digits are used. Any digital device only understands 0 and 1.It is the primary language of a computer that the computer understands directly, the number system which has only two digits is called a binary number system so we can say that the computer can understand only binary codes. Binary codes have only two digits 0 and 1 since the computer only understands the binary signal i.e. 0 and 1 and the computer's circuit i.e. the circuit recognizes these binary codes and converts it into electrical signals. In this, 0 means Low /off and 1 means High/ On.

2.            Assembly Language: - We use symbols in assembly language because machine language is difficult for humans, so assembly language was used to make communication with the computer easier. That is why it is also called symbol language. Sometimes it is also called low-level language. But one thing must be understood that the computer understands only and only the language of the machine. So the computer needs a special type of program, called assembler, to understand the assembly language. The assembler converts programs written in assembly language into machine language so that the program written by us can be understood by the computer. Assembly language is the second generation of programming language.

 

3.            High-Level Language: - Symbols were used in assembly language, so it was difficult to write a program with only symbols, so the need was felt for a language that uses the alphabet of ordinary English or we can say it that we can understand and write easily. Writing and understanding high-level language is much easier than assembly language, so it is quite popular in the computer world with the help of which it became very easy to write many programs. As the assembler was used to convert assembly language to machine language, a special type of software called compiler is used to convert high-level language to machine language. Some of the major high-level programming languages are C, C ++, JAVA, HTML, PASCAL, Ruby, etc.

Compiler, Interpreter, Assembler.

A compiler, interpreter, and assembler are three different types of software programs used in the process of programming and software development.

 

Compiler:

A compiler is a software program that converts the source code written in a high-level programming language into machine code, which can be executed directly by a computer's CPU. It is used to create standalone executable files that can be run on a specific platform. The compiler takes the entire source code as input, performs a series of checks and optimizations, and then generates the executable code.

 

Interpreter:

An interpreter is a software program that executes the source code line by line. Instead of generating machine code, it translates the source code into an intermediate code, which is then executed by the interpreter. This type of program is often used in scripting languages, where code is interpreted at runtime. An interpreter is slower than a compiler because it needs to read and interpret each line of code each time the program is run.

 

Assembler:

An assembler is a software program that converts assembly language into machine code. Assembly language is a low-level programming language that uses mnemonic codes to represent instructions that can be executed directly by a computer's CPU. Assemblers are used to create executable files and libraries that can be linked with other code. Unlike compilers and interpreters, assemblers work directly with machine code, making them very efficient but also very difficult to use.

In summary, compilers, interpreters, and assemblers are all used to translate human-readable code into machine-executable code, but they do it in different ways and for different purposes.

ALGORITHM

An algorithm is a finite sequence of well-defined instructions, typically used to solve a class of specific problems or to perform a computation.

Characteristics of an Algorithm

Not all procedures can be called an algorithm. An algorithm should have the following characteristics −

·        Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning.

·        Input − An algorithm should have 0 or more well-defined inputs.

·        Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output.

·        Finiteness − Algorithms must terminate after a finite number of steps.

·        Feasibility − Should be feasible with the available resources.

·        Independent − An algorithm should have step-by-step directions, which should be independent of any programming code.

 

Algorithm example: Check whether a number is prime or not

Step 1: Start

Step 2: Declare variables n, i, flag.

Step 3: Initialize variables

        flag ← 1

        i ← 2 

Step 4: Read n from the user.

Step 5: Repeat the steps until i=(n/2)

     5.1 If remainder of n÷i equals 0

            flag ← 0

            Go to step 6

     5.2 i ← i+1

Step 6: If flag = 0

           Display n is not prime

        else

           Display n is prime

Step 7: Stop

Limitations of algorithm

 

Limited by the input: An algorithm is limited by the input data it receives. If the input is incorrect or incomplete, the algorithm may not be able to produce the desired output.

Limited by the complexity of the problem: Some problems are so complex that no algorithm can solve them efficiently. This is known as the computational complexity of the problem.

Limited by the computational resources: Algorithms require computational resources such as memory and processing power. If the resources are limited, the algorithm may not be able to solve the problem efficiently.

Limited by the accuracy of the data: Algorithms rely on accurate data to produce correct results. If the data is inaccurate or contains errors, the algorithm may produce incorrect results.

Limited by the assumptions made: Algorithms are often based on assumptions about the data or the problem being solved. If the assumptions are incorrect, the algorithm may produce incorrect results.

Limited by the time constraint: Some problems require a solution within a specific time frame. If the algorithm cannot produce a solution within the time limit, it may not be useful.

Limited by the programmer's ability: The effectiveness of an algorithm is limited by the skill and experience of the programmer who created it. A poorly designed algorithm may not produce the desired results, even if the problem is well-defined.

Flow chart

 

A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a task.

 

Example

 find the HCF of two given numbers



 





 % means store the remainder of expression i.e.

X = 5 % 2

so the value of X would be 1 ( remainder of 5/2 ) 

 

Pseudo code:

 to check whether a given number is prime or not

In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine reading. It typically omits details that are essential for machine understanding of the algorithm, such as variable declarations and language-specific code.

        Flag= 1, i=2

         Read n

 Repeat until i=(n/2)

     If remainder of n÷i equals 0

            flag = 0

            i =i+1

    end if

end repeat

If flag = 0

           Display n is not prime

        else

           Display n is prime

End if

////

Conditions in pseudo code

 

Pseudo code is a simple language used to express the logic of a computer program algorithm. It is not a real programming language, but it is used to describe the steps in an algorithm using English-like statements. Here are some common conditions used in pseudo code:

 

IF/THEN: This is used to check a condition and execute a set of instructions if the condition is true.

Example:

IF x > 0 THEN

PRINT "x is positive"

END IF

 

IF/THEN/ELSE: This is used to check a condition and execute one set of instructions if the condition is true, and another set of instructions if the condition is false.

Example:

IF x > 0 THEN

PRINT "x is positive"

ELSE

PRINT "x is negative or zero"

END IF

 

WHILE: This is used to execute a set of instructions repeatedly while a condition is true.

Example:

WHILE x > 0 DO

PRINT x

x = x - 1

END WHILE

 

FOR: This is used to execute a set of instructions a specified number of times.

Example:

FOR i = 1 TO 10 DO

PRINT i

END FOR

 

SWITCH/CASE: This is used to select one of several sets of instructions to execute based on the value of a variable.

Example:

SWITCH grade

CASE "A"

PRINT "Excellent"

CASE "B"

PRINT "Good"

CASE "C"

PRINT "Fair"

CASE "D"

PRINT "Poor"

CASE ELSE

PRINT "Invalid grade"

END SWITCH

Pseudo code loop

 

Loops in pseudo code

 

In pseudo code, loops are used to execute a block of code repeatedly until a certain condition is met. There are different types of loops, such as "for" loops, "while" loops, and "do-while" loops, which can be used depending on the specific use case. Here are some examples of how loops can be expressed in pseudo code:

 

For loop:


for i = 1 to 10

    // code to be executed

end for

This loop will execute the code inside the loop body 10 times, with the value of i starting at 1 and incrementing by 1 each time through the loop.

 

While loop:

while condition

    // code to be executed

end while

This loop will execute the code inside the loop body repeatedly as long as the condition is true.

 

Do-while loop:

javascript

Copy code

do

    // code to be executed

while condition

This loop will execute the code inside the loop body at least once, and then repeatedly as long as the condition is true.

 

Nested loops:

 

for i = 1 to 10

    for j = 1 to 5

        // code to be executed

    end for

end for

This is an example of a nested loop, where one loop is inside another. In this case, the code inside the inner loop will be executed 5 times for each iteration of the outer loop, resulting in a total of 50 executions of the inner loop code.

 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home