1//<-- CLI SHELL MODE -->
2// =============================================================================
3// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4// Copyright (C) ????-2008 - INRIA
5//
6//  This file is distributed under the same license as the Scilab package.
7// =============================================================================
8// <-- ENGLISH IMPOSED -->
9funcprot(0);
10deff('[y]=t(x)',[
11'y=0'
12'if x>0 then'
13'  if x==1 then '
14'    return'
15'  else '
16'    if x==2 then '
17'       y=10'
18'    else '
19'       for u=1:x, '
20'         y=y+u,'
21'       end,'
22'       return'
23'    end'
24'  end'
25'else '
26'  for u=1:-x, '
27'    if u==4 then '
28'      return,'
29'    else '
30'      y=u,'
31'    end'
32'  end'
33'end'])
34//
35if t(0)<>0 then bugmes();quit;end
36if t(1)<>0 then bugmes();quit;end
37if t(-1)<>1 then bugmes();quit;end
38//
39t1=t;
40if t(0)-t1(0)<>0 then bugmes();quit;end
41if t(1)-t1(1)<>0 then bugmes();quit;end
42if t(-1)-t1(-1)<>0 then bugmes();quit;end
43//==========================================================================
44//test of break
45//==========================================================================
46// for in macro
47//--------------------------------------
48deff('[k]=tt1()','k=0,for i=1:5 ,k=k+1;if k==3 then break,end,end,k=k+1')
49if tt1()<>4 then bugmes();quit;end
50if tt1()<>4 then bugmes();quit;end
51clear tt1
52deff('[k]=tt1()',[
53'k=0,';
54'for i=1:5 ,';
55'  k=k+1;';
56'  if k==3 then break,end,';
57'  if k==-1 then 1,end,';
58'end,k=k+1'])
59if tt1()<>4 then bugmes();quit;end
60if tt1()<>4 then bugmes();quit;end
61clear tt1
62deff('[k]=tt1()',[
63'k=0,';
64'for i=1:5 ,';
65'  k=k+1;';
66'  if k==3 then break,end,';
67'  for j=1:5,j,end,';
68'end,';
69'k=k+1'])
70if tt1()<>4 then bugmes();quit;end
71if tt1()<>4 then bugmes();quit;end
72// while
73//----------------------------------------
74deff('[k]=tt1()','k=0,while k<10 ,k=k+1;if k==3 then break,end,end,k=k+1')
75if tt1()<>4 then bugmes();quit;end
76if tt1()<>4 then bugmes();quit;end
77clear tt1
78deff('[k]=tt1()',[
79'k=0,';
80'while k<10 ,';
81'  k=k+1;';
82'  if k==3 then break,end,';
83'  if k==-1 then 1,end,';
84'end,k=k+1'])
85if tt1()<>4 then bugmes();quit;end
86if tt1()<>4 then bugmes();quit;end
87clear tt1
88deff('[k]=tt1()',[
89'k=0,';
90'while k<10 ,';
91'  k=k+1;';
92'  if k==3 then break,end,';
93'  for j=1:5,j,end,';
94'end,';
95'k=k+1'])
96if tt1()<>4 then bugmes();quit;end
97if tt1()<>4 then bugmes();quit;end
98//
99// keyboard mode
100//------------------------
101k=0;while k<10 ,k=k+1;if k==3 then break,end,end,k=k+1;
102if k<>4 then bugmes();quit;end
103k=0;while k<10 ,k=k+1;if k==3 then break,end,end,
104k=k+1;
105if k<>4 then bugmes();quit;end
106k=0;for  i=1:5 ,k=k+1;if k==3 then break,end,end,k=k+1;
107if k<>4 then bugmes();quit;end
108k=0;for  i=1:5 ,k=k+1;if k==3 then break,end,end,
109k=k+1;
110if k<>4 then bugmes();quit;end
111//
112k=0;while k<10,if k==0 then break,end,k=k+1;end,k=k+1;
113if k<>1 then bugmes();quit;end
114k=0;while k<10,if k==0 then break,end,k=k+1;end,
115k=k+1;
116if k<>1 then bugmes();quit;end
117k=0;for i=1:5,if k==0 then break,end,k=k+1;end,k=k+1;
118if k<>1 then bugmes();quit;end
119k=0;for i=1:5,if k==0 then break,end,k=k+1;end,
120k=k+1;
121if k<>1 then bugmes();quit;end
122//==========================================================================
123//test of continue
124//==========================================================================
125//in a for
126//----------
127n=3;
128c=[];for k=1:5,if k==n then continue,end,c=[c,k];end
129if or(c<>[1 2 4 5]) then bugmes();quit;end
130n=5;
131c=[];for k=1:5,if k==n then continue,end,c=[c,k];end
132if or(c<>[1 2 3 4]) then bugmes();quit;end
133deff('c=foo(n)','c=[];for k=1:5,if k==n then continue,end,c=[c,k],end')
134if or(foo(3)<>[1 2 4 5]) then bugmes();quit;end
135if or(foo(5)<>[1 2 3 4]) then bugmes();quit;end
136n=3;
137c=[];for i=1:3,for k=1:4,if k==n&i==2 then continue,end,c=[c,k];end;end
138if or(c<>[1,2,3,4, 1,2,4, 1,2,3,4]) then bugmes();quit;end
139n=4;
140c=[];for i=1:3,for k=1:4,if k==n&i==2 then continue,end,c=[c,k];end;end
141if or(c<> [1,2,3,4, 1,2,3, 1,2,3,4]) then bugmes();quit;end
142deff('c=foo(n)','c=[];for i=1:3,for k=1:4,if k==n&i==2 then continue,end,c=[c,k];end;end')
143if or(foo(3)<>[1,2,3,4, 1,2,4, 1,2,3,4]) then bugmes();quit;end
144if or(foo(4)<>[1,2,3,4, 1,2,3, 1,2,3,4]) then bugmes();quit;end
145//in a while
146//----------
147//
148n=3;
149c=[];k=0;while k<5,k=k+1;if k==n then continue,end,c=[c,k];end
150if or(c<>[1 2 4 5]) then bugmes();quit;end
151n=5;
152c=[];k=0;while k<5,k=k+1;if k==n then continue,end,c=[c,k];end
153if or(c<>[1 2 3 4]) then bugmes();quit;end
154deff('c=foo(n)','c=[];k=0;while k<5,k=k+1;if k==n then continue,end,c=[c,k],end')
155if or(foo(3)<>[1 2 4 5]) then bugmes();quit;end
156if or(foo(5)<>[1 2 3 4]) then bugmes();quit;end
157n=3;
158c=[];for i=1:3,k=0;while k<4,k=k+1;if k==n&i==2 then continue,end,c=[c,k];end;end
159if or(c<>[1,2,3,4, 1,2,4, 1,2,3,4]) then bugmes();quit;end
160n=4;
161c=[];for i=1:3,k=0;while k<4,k=k+1;,if k==n&i==2 then continue,end,c=[c,k];end;end
162if or(c<> [1,2,3,4, 1,2,3, 1,2,3,4]) then bugmes();quit;end
163clear foo
164deff('c=foo(n)','c=[];for i=1:3,k=0;while k<4,k=k+1;if k==n&i==2 then continue,end,c=[c,k];end;end')
165if or(foo(3)<>[1,2,3,4, 1,2,4, 1,2,3,4]) then bugmes();quit;end
166if or(foo(4)<>[1,2,3,4, 1,2,3, 1,2,3,4]) then bugmes();quit;end
167