July 2019

String Function


LEN Used to find the Length of a String
Syntax LEN(string)
Example PRINT LEN(“Hello India”)
output 11

 
MID$ Used to fetch sub-string from main String
Syntax MID$(string,start,integer) Where, string=actual string start=starting position to fetch sub-string integer=no. of characters from the main string from start position.
Example PRINT MID$(“Hello India”,7,5)
Output India
   
RIGHT$ Used to fetch sub-string of given characters from main String from right side
Syntax RIGHT$(String, integer) Where, string=actual string integer=no. of characters from the main string from right side.
Example PRINT RIGHT$(“Hello India”,5)
output India
 
RIGHT$ Used to fetch sub-string of given characters from main String from left side
Syntax LEFT$(String, integer) Where, string=actual string integer=no. of characters from the main string from left side.
Example PRINT LEFT$(“Hello India”,5)
output Hello
 

Debugging is the process of detecting and correcting the syntax errors in a program.
This consists of two stages:
  1. Systematic desk checking
  2. Translator system checking
   

1. Desk Checking
  When a program is completed, a thorough desk check will eliminate many needless errors. This check may include are view by a second person who is an expert in computer programming.


2. Translator Checking

BASIC system has certain rules which must be followed, such as rules for naming variable and for using punctuation. If rules are not followed or if the instructions are not coded properly, the translator system will detect these errors during the translation process.


Some BASIC systems do a line-by-line syntax check as the lines are being typed. Errors in a line are caught immediately even before the next line is typed in.

A variable is a data name that is used to store a data value which change during the program execution. The quantities which change during the program execution, these quantities are called variables
There are two types of Variables:
  1. Numeric variables
  2. String variables
Numeric variables create locations in computer memory for storing numeric constant while string variables do the same for string constants.


 Numeric Variables Numeric variables can be any single letter of the alphabet or any single letter of the alphabet followed by one of the numerals 0, 1, 2, ….., 9.Thus, any of the following 286 entities could be used as numeric variables:



Note that a numeric variable should start with an alphabet and it should not contain any special character.


String Variables String constant should be handled by string variables. The method of naming and handling string constant differ a great deal from one system to the other. In most systems, the string variables are designated by a single alphabet followed by a dollar sign.

Thus, valid string variables are:

A$, B$, C$,……., Z$

In such a system there can be only 26 string variables.

Examples of naming string items are:

 Items                       Possible names

NAME                             N$
COUNTRY                       C$
YEAR                               Y$
PROFESSION                  P$
SEX                                  S$      And so on.

It should be remembered that any string variable can be used to store any string constant. There are certain systems that allow a string variable name to be any numeric variable name followed by a dollar sign.

Example of this type of variables are:

A$, A2$, X2$, Y$

In this case a total of 286 string variables could be used.

What is Looping?
Looping refers to the repeated use of one or more steps.
There are two types of loops.
  • Fixed Loop: Fixed loop is the loop where the operations are repeated a fixed number of times. In this case, the values of the variables inside the loop have no effect on the number of times that the looping operation is performed.
  • Variable Loop: Variable loop is the loop where the operations are repeated until a specified condition is met. Here, the number of times that the loop is repeated may vary. Searching for a particular item in a list of items is an example of variable loop.
Loops are also referred to as backward jumps. These jumps may occur either after meeting a specified condition in the process or after doing a certain computation.

 LOOPING – THE FOR…..NEXT STATEMENT The FOR…NEXT statement in BASIC is such a control structure. The FOR…NEXT statement is very useful when a program requires that a set of instruction be executed repeatedly a given number of times.
The syntax of FOR…NEXT is as below:








Here u is a numeric variable while e1, e2 and e3 may be numeric constant, variables, or expressions. - u controls the looping operation and therefore it is known as the control variable of the loop.

- e1 is the initial value of u.

- e2 is the final value of u.

- e3 is the increment value assigned to u for every repetition of the loop.

- The step e3 may be positive or negative, but it should not be zero to avoid infinite looping.

- The STEP e3 is optional. If it is not present, a value of +1 is assumed for e3.

- The body of the loop consists of all statements between the FOR and the NEXT   statements.

The flowchart of ‘FOR…NEXT’ statement is as below:


 
 Counter – A numeric variable used as the loop counter.
  • Start and End – The initial and final value of the counter.
  • Increment/Decrement – The amount the counter is changed each time enough the loop.
Example :
FOR I = 1 TO10
PRINT “COMPUTER”

NEXT I
Nesting the Loops There are several problems which involve two or more loops and many times they are contained within each other.
A loop within another loop is known as nested loop.

  









Jumps in FOR….NEXT Loops
 A jump from one statement to another within a loop is allowed. It is also permitted to jump out of a loop but it is prohibited to jump into a loop. When a jump is made out of a loop the value of the control variable is available and can be used, if necessary. The value of the variable would be the latest value the variable had inside the loop. Whenever such a jump is made, it is always desirable to print the latest value of the control variable to know at what stage the jump was made.

 While trying to use the FOR…..NEXT loop, the following Points to be Remember
1) The control variable should not be changed inside the loop.
2) The control variable can be used in the body of calculations as one of the variables of an expression.
3) When loops are nested they should use different control variable names.
4) The control variable value is not defined after the loop is completed in the normal way.
5) Do not jump into a loop.
6) A jump out of a loop is permitted and when it is done, the value of the control variable is available for use, if necessary.
7) While nesting loops, care should be taken to avoid overlaps.
8) When dealing with non integer variables in FOR statement one should be careful about the rounding off errors.

WHILE….WEND STATEMENT
WHILE and WEND statements in pair executes a series of statements in a loop as long as given condition is true.WHILE…..WEND statement is an entry controlled loop statement. The general form is  

WHILE[condition]
……………..
……………..
……………..
……………..  
WEND


 Flowchart:




  When the WHILE statement is encountered, the condition is evaluated. If the condition is true, the statements between WHILE and WEND are executed and the control is returned to back to the WHILE statement. The condition is again tested and if it is still true, the process is repeated. If it is not true, the execution returns to the statement immediately following WEND.   This kind of loop processing is used when we don’t know how many times the loop should be evaluated.

EXAMPLE:
CLS
I = 1;
 WHILE I < 10
  PRINT I;
  I = I + 1;
 WEND
END
    echo "I like PHP";
 

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget