循环语句: 1.for 变量 from 起点 by 步长 to 终点 do 语句 od 2.while 条件 do 语句 od 3.for 变量 in 集合 while 条件 do 语句 od
条件语句: 1.if 条件 then 语句 fi 2.if 条件 then 语句 else 语句 fi 3.if 条件 then 语句 elif 语句 (elif…) else 语句 fi 退出语句:exit退出循环 return退出过程
>x:=0:for I from 1 to 100 do if x>100 then exit else x:=x+I if od:x; >restart:x:=0:j:=0:while j<=100 do x:=x+j:j:=j+1 od:x;
过程函数: 利用程序语句及maple命令可以编写一些应用程序,并且这些程序在maple中可以当做一个命令或函数来使用,并且可以利用maple将程序与其它一些语言(如C语言等)转换。 过程函数是为解决某些特定问题,将一些命令组合在一起作成的maple可以直接调用的函数。 过程函数的格式: 过程名:=proc(参数1,参数2,……) local L1,L2,……; 局部变量 global G1,G2,……; 全局变量 options 选项1,选项2,……; 选项部分 description `字符`; 描述部分 过程体; maple语言 end 过程函数必须加结束语句 过程中参数可以是空的;如:proc() 也可以加说明:用 :: 参数类型 限制参数类型;如:proc(x :: numeric,y :: numeric) 过程两个参数,为数字。 参数也可以用args代表所有实际输入的参数,并可用nargs测量参数的长度。如:求数列最大值的过程。
> Max:=proc() > local i,m; > if nargs=0 then RETURN(FAIL) fi;#测量参数列长度 > m:=args[1]; > for i from 2 to nargs do > if args>m then m:=args fi; > od; > m; > end: > Max(2,5,4,7,4,6,4); |