119,救火啊!`~~~`(50分)

I

issept

Unregistered / Unconfirmed
GUEST, unregistred user!


小弟我遇到点麻烦,现在头都大了。是关于函数的。
If语句和Case语句的用法、作用、以及一些相关知识请各位前辈指点!
谢谢!
 
case可以代替一堆堆的if else if
好像也没什么可说的,呵呵。
 

不懂的地方,按F1就行了。119救不了你的。
 
if J <> 0 then Result := I/J;

The syntax of an if...then...else statement is

if expression then statement1 else statement2

where expression returns a Boolean value. If expression is True, then statement1 is executed
otherwise statement2 is executed. For example,

if J = 0 then

Exit
else
Result := I/J;

The then and else clauses contain one statement each, but it can be a structured statement. For example,

if J <> 0 then

begin
Result := I/J;
Count := Count + 1;
end
else if Count = Last then
Done := True
else
Exit;


The case statement

case I of

1..5: Caption := 'Low';
6..9: Caption := 'High';
0, 10..99: Caption := 'Out of range';
else
Caption := '';
end;

is equivalent to the nested conditional

if I in [1..5] then

Caption := 'Low'
else if I in [6..10] then
Caption := 'High'
else if (I = 0) or (I in [10..99]) then
Caption := 'Out of range'
else
Caption := '';

Other examples of case statements:

case MyColor of

Red: X := 1;
Green: X := 2;
Blue: X := 3;
Yellow, Orange, Black: X := 0;
end;

case Selection of

Done: Form1.Close;
Compute: CalculateTotal(UnitCost, Quantity);
else
Beep;
end;
 
case不能判断字符串,if 可以
 
找本电子书看看,不是更好?
 
case 也可以用来判断字符串只不过要和Tstring类型连用。
[:D]
 
找本基础的书系统的看看
 
最好是找本语法方面的书来看一下。
case不能判断字符串、浮点数。
if的应用要广泛的多。
 
谢谢大家,不过cwmdelpher,你写的那个是什么,看不懂,最好说明一下,谢谢![:D]
 

Similar threads

D
回复
49
查看
1K
DarwinZhang
D
回复
4
查看
147
出人头地
顶部