⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c51复合语句和条件语句2.htm

📁 单片机教程 用c语言实现编程 可以大大缩短我们的开发周期
💻 HTM
📖 第 1 页 / 共 3 页
字号:
	   {
			showAlert ("用户名不能为空");
			thisform.account.focus();
			return false;
	   }
	   
	   if (password == "")
	   {
		showAlert ("密码不能为空");
		thisform.password.focus();
		return false;
	   }
	   return true;
}
function top_joined(value)
{
	if (value != "")
	{
		var action;
		action = value.split("_");
		if (action[0] == "league")
		{
			window.location.href="/league/index.php?gid=" + action[1];
		}
		if (action[0] == "acti")
		{
			window.location.href="/league/activity/acti_mana_index.php?t_id=" + action[1];
		}

	}
}

function copyurl(url)
{
	try{
		clipboardData.setData('Text',url);
		showAlert('已经把该社团网址复制到系统剪贴板,您可以使用(Ctrl+V或鼠标右键)粘贴功能,通过其他软件记录或发送给您的朋友。')
	}
	catch(e){}
}
function add_favorite(uid, url, name)
{
	window.open("/personal/favorite/add.php?member_id="+uid+"&url="+url+"&name="+name,'_blank','width=400,height=220,toolbar=0,locationbar=0,menubar=0,statbar=0'); 
	return false;
}

// 提示登录
function alertlert_login()
{
	showAlert('对不起,您目前没有权限,请先登录!');
	document.login_form1.account.focus();
}


//申请加入社团
function con_join(con_gid)
{
	showConfirm("您确认加入本社团吗?","window.location.href='/league/apply.php?g_id="+con_gid+"';","");
}


//退出本社团
function con_quiet(con_gid,con_uid)
{
	showConfirm("您确认退出本社团吗?","window.location.href='/league/member/quiet_member.php?g_id="+con_gid+"&q_uid="+con_uid+"';","");
}

</SCRIPT>
<!-- 回复框 -->
<DIV id=background style="DISPLAY: none"></DIV>
<DIV id=postbox 
style="DISPLAY: none; Z-INDEX: 50; LEFT: 769px; WIDTH: 600px; POSITION: absolute; TOP: 271px">
<FORM name=reply_comment action=/league/comment/index.php?gid=514465 method=post 
target=hidden_frame><INPUT id=act type=hidden value=add name=act> <INPUT id=r_id 
type=hidden name=r_id> <INPUT id=t_id type=hidden name=t_id> <INPUT id=f_uid 
type=hidden name=f_uid> 
<TABLE cellSpacing=0 cellPadding=0 width="70%" border=0>
  <TBODY>
  <TR>
    <TD height=13>&nbsp;</TD></TR>
  <TR>
    <TD class=box_common height=26>&nbsp;<SPAN 
      class=font_common_title>回复评论</SPAN></TD></TR></TBODY></TABLE>
<TABLE class=box_common01 cellSpacing=0 cellPadding=0 width="70%">
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=8 cellPadding=0 width="100%" bgColor=#ffffff 
        border=0><TBODY>
        <TR>
          <TD class=font_common vAlign=top align=right height=63>内容:</TD>
          <TD class=font_common vAlign=top><TEXTAREA class=input_box01 id=input_area name=input_area rows=6 cols=48></TEXTAREA></TD></TR>
        <TR>
          <TD class=font_common vAlign=top align=right width="15%">原文:</TD>
          <TD class=font_common style="LINE-HEIGHT: 18px" vAlign=top 
            width="85%"><SPAN class=gray id=past_type></SPAN></TD></TR>
        <TR>
          <TD class=font_common vAlign=top align=middle colSpan=2><INPUT class=btn01 onclick=javascript:hidden_reply();submit_post(document.reply_comment); type=button value=发表 name=queding> 
            &nbsp;&nbsp; <INPUT class=btn01 onclick=hidden_reply(); type=reset value=取消> 
        </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></DIV><!-- 回复框 -->
<DIV id=mainBox>
<DIV id=mainBoxBg>
<TABLE class=module_title cellSpacing=0 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD class=corner_left></TD>
    <TD class=corner_center><A 
      href="http://www.5jia1.com/league/?gid=514465">首页</A>&nbsp;&gt;&nbsp;<A 
      href="http://www.5jia1.com/league/blog/blog_index.php?gid=514465">社团文集</A>&nbsp;&gt;&nbsp;<A 
      href="http://www.5jia1.com/league/blog/show_comm.php?bid=361538">第十一课 
      C51复合语句和条件语句</A></TD>
    <TD class=corner_right></TD></TR></TBODY></TABLE>
<DIV class=module_content>
<DIV class=module_content_line>
<DIV class=bg>
<TABLE cellSpacing=10 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD align=middle>
      <TABLE class=box_common cellSpacing=1 cellPadding=5 width="100%" 
        border=0><TBODY>
        <TR class=box_common_title>
          <TD colSpan=2>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD width="35%"><B>第十一课 C51复合语句和条件语句</B></TD>
                <TD align=right width="65%">作者: <A 
                  href="http://www.5jia1.com/personal/?member_id=505887" 
                  target=_blank>张文俊</A> &nbsp;&nbsp;2007-08-15 
                  09:06:51&nbsp;&nbsp; </TD></TR></TBODY></TABLE></TD></TR>
        <TR class=box_content>
          <TD vAlign=top align=middle width="10%"><A 
            href="http://www.5jia1.com/personal/?member_id=505887" 
            target=_blank><IMG class=box01 height=98 
            src="11.files/s_0_personal_photo_505887.jpg" width=98 vspace=5 
            border=0></A><BR><IMG height=14 src="11.files/icon_boy.gif" width=14 
            border=0>&nbsp; <A 
            href="http://www.5jia1.com/personal/?member_id=505887" 
            target=_blank>张文俊</A> </TD>
          <TD>
            <TABLE class="font_content  autowrap" cellSpacing=12 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD class=line_h20 style="WIDTH: 790px">
                  <DIV style="OVERFLOW-X: auto; WIDTH: 100%">
                  <P style="WORD-BREAK: break-all; LINE-HEIGHT: 150%"><SPAN 
                  style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ascii-font-family: &#718;&#805;; mso-hansi-font-family: &#718;&#805;; mso-bidi-font-family: Tahoma"><FONT 
                  face=宋体></FONT></SPAN><SPAN lang=EN-US 
                  style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: "></SPAN>
                  <P>
                  <P>曾经在BBS上有朋友问过我{}是什么意思?什么作用?在&nbsp; C&nbsp; 
                  中是有不少的括号,如{},[],()等,确实会让一些初入门的朋友不解。在 VB 等一些语言中同一个()号会有不一样的 
                  作用,它能用于组合若干条语句形成功能块,能用做数组的下标等,而在 C 中括号的分 
                  工较为明显,{}号是用于将若干条语句组合在一起形成一种功能块,这种由若干条语句组合 
                  而成的语句就叫复合语句。复合语句之间用{}分隔,而它内部的各条语句还是需要以分号“;” 
                  结束。复合语句是允许嵌套的,也是就是在{}中的{}也是复合语句。复合语句在程序运行时,{}中的各行单语句是依次顺序执行的。单片机C语言中能将复合语句视为一条单语句,也就是说 
                  在语法上等同于一条单语句。对于一个函数而言,函数体就是一个复合语句,也许大家会因 
                  此知道复合语句中不单能用可执行语句组成,还能用变量定义语句组成。要注意的是在 
                  复合语句中所定义的变量,称为局部变量,所谓局部变量就是指它的有效范围只在复合语句 
                  中,而函数也算是复合语句,所以函数内定义的变量有效范围也只在函数内部。下面用一段简单的例子简单说明复合语句和局部变量的使用。</P>
                  <P>#include&nbsp; &lt;at89x51.h&gt;</P>
                  <P>#include&nbsp; &lt;stdio.h&gt;</P>
                  <P>void&nbsp; main(void)</P>
                  <P>{</P>
                  <P>unsigned&nbsp; int&nbsp; a,b,c,d;&nbsp; //这个定义会在整个 main 
                  函数中?</P>
                  <P>SCON&nbsp; =&nbsp; 0x50;&nbsp; //串行口方式 1,允许接收 TMOD&nbsp; 
                  =&nbsp; 0x20;&nbsp; //定时器 1 定时方式 2</P>
                  <P>TH1&nbsp; =&nbsp; 0xE8;&nbsp; //11.0592MHz&nbsp; 1200 波特率 
                  TL1&nbsp; =&nbsp; 0xE8;</P>
                  <P>TI&nbsp; =&nbsp; 1;</P>
                  <P>TR1&nbsp; =&nbsp; 1;&nbsp; //启动定时器</P>
                  <P>a&nbsp; =&nbsp; 5; b&nbsp; =&nbsp; 6; c&nbsp; =&nbsp; 
7;</P>
                  <P>d&nbsp; =&nbsp; 8;&nbsp; //这会在整个函数有效</P>
                  <P>printf("0:&nbsp; %d,%d,%d,%d\n",a,b,c,d);</P>
                  <P>{&nbsp;&nbsp;&nbsp;&nbsp; //复合语句 1</P>
                  <P>unsigned&nbsp; int&nbsp; a,e;&nbsp; //只在复合语句 1 中有效</P>
                  <P>a&nbsp; =&nbsp; 10,e&nbsp; =&nbsp; 100;</P>
                  <P>printf("1:&nbsp; %d,%d,%d,%d,%d\n",a,b,c,d,e);</P>
                  <P>{&nbsp; //复合语句 2</P>
                  <P>unsigned&nbsp; int&nbsp; b,f;&nbsp; //只在复合语句 2 中有效</P>
                  <P>b&nbsp; =&nbsp; 11,f&nbsp; =&nbsp; 200;</P>
                  <P>printf("2:&nbsp; %d,%d,%d,%d,%d,%d\n",a,b,c,d,e,f);</P>
                  <P>}//复合语句 2 结束</P>
                  <P>printf("1:&nbsp; %d,%d,%d,%d,%d\n",a,b,c,d,e);</P>
                  <P>}//复合语句 1 结束</P>
                  <P>&nbsp;</P>
                  <P>printf("0:&nbsp; %d,%d,%d,%d\n",a,b,c,d);</P>
                  <P>while(1);</P>
                  <P>}</P>
                  <P>运行结果:</P>
                  <P>0:5,6,7,8</P>
                  <P>1:&nbsp; 10,6,7,8,100</P>
                  <P>2:&nbsp; 10,11,7,8,100,200</P>
                  <P>1:&nbsp; 10,6,7,8,100</P>
                  <P>0:5,6,7,8 结合以上的说明想想为何结果会是这样。</P>
                  <P>读完前面的文章大家都会大概对条件语句这个概念有所认识吧?是的,就如学习语文中 的条件语句一样,C 语言也一样是“如果 
                  XX 就 XX”或是“如果 XX 就 XX 不然 XX”。也就是 
                  当条件符合时就执行语句。条件语句又被称为分支语句,也有人会称为判断语句,其关键字 是由 if 
                  构成,这大众多的高级语言中都是基本相同的。C 语言供给了 3 种形式的条件语句:</P>
                  <P>1:&nbsp; if&nbsp; (条件表达式)&nbsp; 语句 
                  当条件表达式的结果为真时,就执行语句,不然就跳过。 如&nbsp; if&nbsp; (a==b)&nbsp; 
                  a++;&nbsp; 当 a 等于 b 时,a 就加 1</P>
                  <P>2:&nbsp; if&nbsp; (条件表达式)&nbsp; 语句 1</P>
                  <P>else&nbsp; 语句 2</P>
                  <P>当条件表达式成立时,就执行语句 1,不然就执行语句 2 如&nbsp; if&nbsp; (a==b)</P>
                  <P>a++;</P>
                  <P>else</P>
                  <P>a--;</P>
                  <P>当 a 等于 b 时,a 加 1,不然 a-1。</P>
                  <P>3:if&nbsp; (条件表达式 1)&nbsp; 语句 1</P>
                  <P>else&nbsp; if&nbsp; (条件表达式 2)&nbsp; 语句 2</P>
                  <P>else&nbsp; if&nbsp; (条件表达式 3)&nbsp; 语句 3</P>
                  <P>else&nbsp; if&nbsp; (条件表达式 m)&nbsp; 语句 n else&nbsp; 语句 
m</P>
                  <P>这是由 if&nbsp; else 语句组成的嵌套,用来实现多方向条件分支,使用应注意 if 和 else 
                  的配对使用,要是少了一个就会语法出错,记住 else 总是与最临近的 if 相配对。一般条件 
                  语句只会用作单一条件或少数量的分支,如果多数量的分支时则更多的会用到下一篇中的开 关语句。如果使用条件语句来编写超过 3 
                  个以上的分支程序的话,会使程序变得不是那么清晰易读。<BR></P>
                  <P></P>
                  <P>
                  <TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -