Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
All articles(文章集合)All Picture(图片集合)All Video(视频集合)
The author:(作者)归海一刀published in(发表于) 2014/2/10 6:47:39 PHP学习宝典-第七章_[PHP教程]
if (TRUE)
print(“This will always print”);
else
print(“This will never print”);
上面的范例与下面的确叙述的是相同的:
if(FALSE)
three = 3;
four = 4;
my_pi = 3.14159;
If ((three = =three) and
(four ===four)and
(three !=four)and
(three< four) and
(three<=four) and
(four>=there) and
(three<=three) and
(my_pi > three) and
(my_pi <=four))
print(“My faith in mathenmatics is restored! ”);
print (“Sure you typed that right?”):
if ((“Marx”<“Mary”)and
(“Mary”<“Marzipan”))
{
print(“Between Marx and Marzipan in the ”);
print(“dictionary, there was Mary .”);
}
strinhg_1 = “00008”;
string _2 = “007”;
string_3 = “00008-OK”;
If(string_2
Print(“string_2 is less than string_1 ”);
If(string_3< string_2)
Print(“string_3 is less than string_2”);
If (string_1 < string_3)
Print(“string_1 is less than string_3”);
if (first - second)
if (first > second)
difference = first - second;
print(“The difference is difference”);
difference = second - first;
print(“There is no difference”);
if(num % 2 = =0)// num为偶数?
if (num > 2)
print(“num is not prime”);
print(“num is odd”);
if (day == 5)
print(“Five golden rings”);
if (day ==4)
print(“Four calling birds”);
if (day ==3)
print(“Three French hens”);
if (day ==2)
print(“Tow turtledoves”;
if (day ==1)
print(“A partridge in a pear tree”);
elseif(day == 4)
elseif(day == 3)
elseif(day == 2)
print(“Two turtledoves”);
elseif(day ==1)
If(female())
Print(“TITLE>The women-only site”);
print(“”);
print(“This site has been specially constructed”);
print(“for women only. No men allowed here!”);
Else
Print(“TITLE>The men-only site”);
print(“for men only. No women allowed here!”);
?>
我们可以不用所有这些print语法,而且两部分支内部都使用HTML程式码,例如:
This site has been specially constructed
For women only. No men allowed here!
for men only. No women allowed here!
switch( expression)
case value -1:
statement-2
…
[break;]
case value-2:
statement-3
statement-4
[default:
default-statement]
switch(day)
case 5:
break;
case4:
case 3:
case 2:
print(“Tow turtledoves”);
default:
这个英文歌词的例子会在2-5于之中输出显示相对应的该行,而在其它日期则列印「A partridge in a pear tree」。 Switch 让人困扰的地方是,一个匹配的case后的所有case都将会执行,直到有break叙述来停止执行。在「partridge」的例子中,break叙述确保了一次只看到歌词中的一行。如果去掉break叙述,则会看到几行都被显示出来。 回圈 恭喜!你刚刚跨过了从script编制到「真正的程式设计」之间的界限了。到目前为止,我们看到的分支结构还算有用,但使用它们完成的计算还是有限的。另一方面,任何带有评算测试和无界限回圈的语言都能够比任何其它语言完成更好的功能,在电脑科学理论中,这一点是很确定的。在PHP中你也许并不需要编写一个C语言编译器,不过请记住这里没有什么天生的语言限制会阻止你这样做。
出处:南方Linux