LoadRunner编程之跳出迭代
51Testing软件测试网3p6pK.Yo
LoadRunner中
提供了函数exit(-1)来结束迭代。 使用return
0 来结束本次迭代,进入下一次迭代。
P2E[&V o1M$N0
H‘X3EL,o7K4]C/L0例子如下:51Testing软件测试网_Ts r5oT
y/Z6C/yx.@0 在运行时设置中,设置迭代次数为5,运行下面的脚本:
‘q:k.k"xj0q0
ne!g k8T:Da1c i0 int i;51Testing软件测试网{g7UP$[R
char aaa[]="test";
2JO#A YxwH‘u0Action()
DmW9SJn;~Q!A0{
O-D}h!m7@n DZ[0
kFo;@}:rwF&d&[3Q0 i=0;51Testing软件测试网.Z;Hd-j R}rg
if
(i==0) {51Testing软件测试网]6yw9]"E x:^J
exit(-1);51Testing软件测试网H7i‘jx/z&M
}
xn9I+TY+J0 51Testing软件测试网/?#t;o,r1v?F4m
lr_output_message("value:%s",aaa);51Testing软件测试网.H7PDIgc:N
51Testing软件测试网4h#U1x_ ]uo
return 0;51Testing软件测试网W&?4_$Q6dI u%`
?
}51Testing软件测试网$~:y?CD6~@
S.k(O&o p| H6PS0结果为:51Testing软件测试网 i*h7ua;wMd7W2{K6^
kI^z_7MQ[0Virtual User scrīpt
started51Testing软件测试网@
l`0EQTp"rR$?
Starting action vuser_init.
‘I@XbY"Y;w0Ending action vuser_init.
q0h)p"M#u},z N"y4t0Running Vuser...
‘HN hRxo3k6{0Starting iteration 1.51Testing软件测试网(`;F.mDaTV G/lg
Starting
action Action.
x A {\PB_gd051Testing软件测试网/q9D,S)R5tNqb
只运行了一次迭代,就结束了。
q
F)T{(^0q1hP051Testing软件测试网6[i$rRE+@1TLk
下面的代码:51Testing软件测试网A0N
Q\W2pBzn-D
{p$f6F)S)s0 int i;51Testing软件测试网"M5~ tq~h)m#A`p|,O‘}
char aaa[]="test";
K$`g7r9g4hM0Action()51Testing软件测试网8`D}0Q:t4i-x
{51Testing软件测试网7qx;\1p\lDP-wqU
51Testing软件测试网3t(BFQ9IZ9Ul-td
i=0;51Testing软件测试网/a)Jchg&Ns
if (i==0)
{
6N9Kb5w‘Y*W \wK0 return
0;
_i$@*^q{;r7ln0 }51Testing软件测试网(P gm(V‘t/V9|}
51Testing软件测试网6lWVc1mw2s*YPs
lr_output_message("value:%s",aaa);
m#pA)t~a‘?051Testing软件测试网,euD!|JHohc&H
return 0;
9\J+s.kM;l/R3]`0}51Testing软件测试网Et-zd-I1f
#Mnjq$K},f)~+HS0结果:51Testing软件测试网[3Uskq hG7y1_
(d}PuM@@6MF0Virtual User scrīpt
started51Testing软件测试网(L-dKLA*W-Zd:CV
Starting
action vuser_init.51Testing软件测试网USyH,}c
Ending action
vuser_init.51Testing软件测试网}Z1Qc6cjzy
lJ
Running Vuser...51Testing软件测试网:m6t
W%t#Z5[
Starting iteration 1.51Testing软件测试网ZN(u2a G!vR
Starting action
Action.
?4EYlb {‘e2A)D@h6F0Ending
action Action.
Y&dK6Z#GgT0Ending
iteration 1.51Testing软件测试网+x#?_7\"C}U
Starting iteration
2.
p+eO w%|_5z2c*}0E.k)p0Starting
action Action.51Testing软件测试网,YJUalM!k/_5B
Ending action
Action.51Testing软件测试网q&M^(E8? e/]#r
TZ+y
Ending iteration 2.
XPr#C(Y6Sh0Starting iteration 3.
wlp#T2o!l0Starting action Action.
D0wbqC2k u E0Ending action Action.
u^(Vx9j?Cz$L1?0Ending iteration 3.51Testing软件测试网g?%@6p*{Uc]
Starting iteration
4.
‘a4[2ExJ)n0Starting action
Action.
wn6r%E:k0h2Q0Ending action
Action.
Gs3wTsn1iC|0Ending iteration
4.
sF1\$uc%q0Starting iteration 5.51Testing软件测试网W~oG0K5W
Starting action
Action.51Testing软件测试网1v9iB1w-EA"^
Ending
action Action.
*S$f8TL5m%h9f6t0Ending
iteration 5.
K5m C4L/i0O‘|5bb0Ending
Vuser...51Testing软件测试网2}*{~6w[$m
h
Starting action vuser_end.51Testing软件测试网iW h5i5u I0Q5_7K \
Ending action
vuser_end.
5M9O#`|3~0Vuser
Terminated.51Testing软件测试网-q*|,b.O"[8jm4H#wM
51Testing软件测试网+@Ec1J@%gw/Ej(J&? Z
51Testing软件测试网 D5G/|*~&S4v c1K|
运行了5次迭代,但是每次迭代运行到lr_output_message("value:%s",aaa)之前都跳出迭代,进行下一次迭代。