LoadRunner Scripting (ii)

Source: Internet
Author: User

Today, my friend asked me about the second LoadRunner script, and I told him there was nothing. To learn a language, basic grammar and thought are important. Now everyone is literate, and that is not every literate person can be a writer. Impossible, because most people do not have the thought of a writer. Programming is an art, we can write the code very beautiful, and why do Chinese programmers call code workers? Foreign programmers are writing a beautiful "prose", and Chinese programmers are writing "explanatory papers". Chinese programmers simply describe a product in terms of their needs by language.

Pull far, recently changed long-winded, hehe! What I'm trying to say is that the basic grammar of the line programming must be understood. The idea of a program is also important. Because I'm also a half tune on programming. So look at my article can only calculate the aftertaste of grammar.

Here's a look at the nested loops example.

Action ()
{
    int  i,j;   Life two variables
    for (i=1;i<=5;i++)   //First heavy cycle, loop 5 times
    {
        if (i==3) break    
            ;   When I equals 3 o'clock, jump out of this heavy circulation
        else
             lr_output_message ("i=%d", I);  Otherwise, enter the value of I for
    
        (j=1;j<=5;j++)  //second cycle, loop 5 times
        {
            if (j==2) break   
                ;   When J equals 2 o'clock, jump out of this heavy loop
            else
             lr_output_message ("j=%d", j);  Otherwise, enter the value of J}}

I added the comments in the code above, so there's no need to explain.

Run Result:

Starting Iteration 1.
Starting action action.
ACTION.C (9): I=1
action.c (): J=1
action.c (9): i=2 action.c
(): J=1 ending
action action.
Ending Iteration 1.

Function

function, usually a small section of the C language program consists of only one main () function. However, in the actual authoring application, developers need to write a large number of user-defined intersection functions, not only in the program to define the function itself, but also in the keynote function module must be the function of the type description, and then to use, and user-defined functions corresponding to the function library, The C Language Integrated development environment (IDE) is provided, and we just call it the line. The so-called predecessors to plant trees, Horong, or seemingly a simple thing, to find its source to do, are a very complex process.

void Ssyhello ()  //Greeting function
{
    lr_output_message ("Hello%s", Lr_get_host_name ());
}
    
int Getbigger (int x,int y)  //Get Maximum function
{
    if (x>y) {return
        x;
    }
    else{return
        y;
    }
    
}
    
Action () {
    int x=10,y=20, result;   DECLARE variable
    
    ssyhello ();  Invisible parameter, no return value function result
    = Getbigger (x,y);
    Lr_output_message ("Getbigger (%d,%d) =%d", x,y,result);  With formal parameters, return value function returns
    
    0;
}

The above program raises the solution, in a nutshell, two functions Ssyhello () and Getbigger () are defined, and the main function action () invokes the preceding two functions.

Run Result:

Starting Iteration 1.
Starting action action.
ACTION.C (4): Hello 2011-20120624yo
action.c: Getbigger (10,20) =20 ending
action action.
Ending Iteration 1.

Dynamic storage mode and static storage mode

We are defining variables that, depending on the location of the definition, are divided into global variables and local variables. I was born in a small county called "Wuyang", in this county is also known as "Wuyang", the former role in the entire county, the latter one only role in his personal. Then there are two kinds of static storage mode and dynamic storage mode from the angle of existence of variable value.

Static storage mode: is the allocation of fixed storage space during program operation.

Dynamic storage: The way in which storage space is dynamically allocated as needed during program operation.

The user storage space can be divided into three parts:

1. Program Area

2. Static Storage Area

3, dynamic storage area

The global variables are all stored in the static storage area, when the program starts to execute to assign the global variable storage area, the program runs to release, in the program execution process they occupy the fixed storage unit, but does not carry on the allocation and the release dynamically.

The dynamic store holds the following data:

(1) function form parameter

(2) automatic variable (local variable without static declaration)

(3) Field protection and return address when function call

The above data, which allocates dynamic space when the function starts to call, frees the space when the function results.

In C, each variable and function has two properties: the data type and the storage category of the data

* AUTO (AUTO) variable

Local variables in a function, such as those not specifically declared as static storage categories, are dynamically allocated storage space.

* Static (statically) declaring local variables

Sometimes you want the value of a local variable in a function to remain without disappearing after the function call ends, and you should specify the local variable to be "static local variable", with the static keyword.

* Register (REGISTER) variable

In order to improve efficiency, the C language allows the value of local variables to be placed in a register in the CPU, which is called "register variable" with the keyword register variable.

 static int C;
    int prime (register int number)//Determine if the prime number {Register int flag=1;
    auto int n;
    For (N=2;N<NUMBER/2 && flag==1;n++) {if (number% n==0) flag=0;    
            
    return (flag);
    The demo function {Auto int b=0 for demo (int a)//static, auto variable;
    int D;
    Static c=3;
    b=b+1;
    c=c+1;
    Lr_output_message (d=%d in "demo () function", d);
    Lr_output_message ("Static c=%d" in the demo () function, c);
    
return a+b+c;   Action () {int a=2,i;
        The variable declaration for (i=0;i<3;i++) {Lr_output_message ("demo () function" section%d runs as follows: ", i+1);
        Lr_output_message ("function demo run result is:%d", demo (a));
    Lr_output_message ("-------------------\n\r"); //Determine whether 13 is a prime number and output a hint message if (prime) ==0 Lr_output_message ("13 is not a prime!").
    "); else Lr_output_message ("13 is prime!")
    
    ");  Lr_output_message ("c=%d", c);
Enter the value of the change return 0; }

Prime number: The number of natural numbers greater than 1, except for 1 and its own cannot be divisible by other numbers. The prime () function is mainly used to determine whether the incoming number is prime.

The demo () function is used to perform variable demonstrations of static and auto types. The Action () function is used to invoke and enter the result.

Run Result:

Starting Iteration 1.
Starting action action.
ACTION.C (): Demo () function section 1th Run as follows: Action.c ()
: Demo () function d=51446257
action.c (): Demo () function in the static c=4
Action.c (32): The function demo run result is: 7
ACTION.C (a):-------------------
    
ACTION.C: the demo () function section 2nd run as follows:
ACTION.C (): Demo () function d=51446257
action.c (): Static c=5
in the demo () function ACTION.C (32): function Demo Run results: 8
action.c:-------------------
    
action.c: Demo () function part 3rd run as follows:
ACTION.C (): d=51446257 action.c in the demo () function
: Static c=6 action.c (32) in the demo () function
: Demo Run results: 9
ACTION.C (a):-------------------
    
action.c (40): 13 is prime!
action.c (km): c=0
Ending action action.
Ending Iteration 1.

Pointer

Pointers are widely used in C language of a data type, pointers can make our program become very flexible, but also let a lot of programmers headaches, inadvertently will make the program error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.