Variables Arithmetic IO

itx0 n x sm axx1 ae s x sm axx 1 ae

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: can use the following shorthand for changing the values of variables. The shorthand form is shown, then the equivalent form is described in comments. dul a=00 obe .; itx=0 n ; x+ +; / sm a:x=x+1 / ae s ; x-; / sm a:x=x-1 / ae s ; x+ 2 =; / sm a:x=x+2 / ae s ; x- 2 =; / sm a:x=x-2 / ae s ; x* 2 =; / sm a:x=x*2 / ae s ; x/ 2 =; / sm a:x=x/2 / ae s ; x% 2 =; / sm a:x=x%2 / ae s ; a+ 20 = .; / ec / t. / sm a:a=a+20 / ae s .; Boolean operators Variables of type b o have the following special operators: ol bo p=TU; ol RE bo q=FLE ol AS; bo r ol ; r=!; p / ""mas"o"o "poie,s r= FLE / ! en nt r opst" o = AS r=p| q |; / "| mas"r,s r= TU / |" en o" o = RE r=p& q &; / "& mas"n" s r= FLE / &" en ad, o = AS r=q| (p / r= FLE | !) / = AS Note that you cannot use "shorthand" operators with Boolean variables. The following does not do what you expect: r ! p =; Mathy example This example shows use of several mathematical functions and operators. / mt eape / ah xml #nld <otem icue isra> #nld <mt> icue cah uignmsaesd sn aepc t; itmi( n an) { cu < "h rcpoa o 1 i "< 101. < ed; ot < Te eircl f 0 s < ./00 < nl cu < "h sur ro o 1 i "< sr(00 < ed; ot < Te qae ot f 0 s < qt1.) < nl cu < "^1.)="< ep1.)< ed; ot < e(00 < x(00 < nl cu < "h rcpoa o 1 i "< 101. < ed; ot < Te eircl f 5 s < ./50 < nl cu < "h sur ro o 1 i "< sr(50 < ed; ot < Te qae ot f 5 s < qt1.) < nl cu < "^1.)="< ep1.)< ed; ot < e(50 < x(50 < nl rtr 0 / ei porm eun ; / xt rga } Here is the example again, but this time with a variable x : #nld <otem icue isra> #nld <mt> icue cah uignmsaesd sn aepc t; itmi( n an) { dul x obe ; x=1.; 00 cu < "h rcpoa o 1 i "< 10x< ed; ot < Te eircl f 0 s < ./ < nl cu < "h sur ro o 1 i "< sr()< ed; ot < Te qae ot f 0 s < qtx < nl cu < "^"< x< " ="< epx < ed; ot < e( < <) < x() < nl x=1.; 50 cu < "h rcpoa o 1 i "< 10x< ed; ot < Te eircl f 5 s < ./ < nl cu < "h sur ro o 1 i "< sr()< ed; ot < Te qae ot f 5 s < qtx < nl cu < "^"< x< " ="< epx < ed; ot < e( < <) < x() < nl rtr 0 / ei porm eun ; / xt rg...
View Full Document

Ask a homework question - tutors are online