| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 20951 人关注过本帖
标题:for循环语句中嵌套if语句 问题~~~
取消只看楼主 加入收藏
vopvcp
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-6-22
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:4 
for循环语句中嵌套if语句 问题~~~
请帮忙确认下如下例子中循环哪里出错,执行的结果到printf("!!!!~~~~~");  。是不是for循环中不能有两个if语句,如果是这样的话,那我想在for循环中加两个判断语句,该如何实现呢....

int fun(int i,j)

{
  for(i=0;i<100;i++)
{
if(i==20)
{
printf("!!!!!");
}
if(i==40)
{
printf("~~~~~~~~~~~~");
}
}

if(i!=20||i!=40)
{
printf("!!!!~~~~~");
}
}

[ 本帖最后由 vopvcp 于 2012-10-29 11:47 编辑 ]
搜索更多相关主题的帖子: fun 如何 
2012-10-29 11:14
vopvcp
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-6-22
收藏
得分:0 
回复 楼主 vopvcp
是 ==  我写错了
2012-10-29 11:47
vopvcp
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-6-22
收藏
得分:0 
回复 4楼 zxd543
int fun(int i,j)
 {
     for(i=0;i<100;i++)
     {
         if(i==20)
         {
             printf("!!!!!");
         }
         if(i==40)
         {
             printf("~~~~~~~~~~~~");
         }
         if(i!=20||i!=40)
         {
             printf("!!!!~~~~~");
         }
     }  
 }

如果是这样的话,那for()循环的第一次是不是就跳出来了!!!
2012-10-29 13:23
vopvcp
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-6-22
收藏
得分:0 
回复 6楼 wp231957
这段代码是我随便写的,我自己也没有编译过,我只是想问下for()语句中是否可以嵌套两个if()语句...
2012-10-29 14:43
vopvcp
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-6-22
收藏
得分:0 
回复 9楼 wp231957
请指教一下还有什么方法可以代替呢....
我的原本代码是:
#include"stdio.h"
#include"dos.h"
#include"string.h"
#include"stdlib.h"
#include"conio.h"


unsigned long Read_VID_DID();
unsigned long ReadPci(unsigned long BusCount);
void ClearScreen(void);

#pragma inline
asm .486p

void main()
{

    clrscr();
    ClearScreen();

    printf("********************- Check LAN type tool -********************* \n");
    printf("*        Corporation Copyright (C) By RD Of   Ver:1.0          * \n");
    printf("**************************************************************** \n");

    printf("\n");
    printf("\n");
    Read_VID_DID();
}


unsigned long Read_VID_DID(unsigned long BusCount)
{
    unsigned long PciData;
   
    for(BusCount=0x80000000;BusCount<0x81000000;BusCount+=0x100)
    {
        PciData=ReadPci(BusCount);

        if(PciData==0x0250197b)                                        //JMC LAN VID:DID  0250:197B
        {
            textcolor(2);
            printf("This is JMC LAN chip! \n");
            textcolor(WHITE);
            system("JMCflash.bat");
        }
        if(PciData==0x817610ec)                                       //RTL LAN VID:DID  0250:197B
            textcolor(2);
            printf("This is RTL LAN chip! \n");
            textcolor(WHITE);
            system("RTLflash.bat");
            

        // return(BusCount);
        
    }

   

            textcolor(4);
            printf("The unknown LAN chip! \n");
            textcolor(WHITE);
            exit(1);
            

        return(PciData);

}

unsigned long ReadPci(unsigned long BusCount)
{
    unsigned long PCIdata;

        asm{
     mov dx, 0cf8h
     mov eax, BusCount
     out dx, eax

     mov dx, 0cfch
     in  eax, dx
     mov PCIdata, eax
    }
    /*unsigned long port_a = 0x0cf8;
    unsigned long port_d = 0x0cfc;

    outport(port_a,BusCount);
    PCIdata=inport(port_d);*/

    return(PCIdata);
}

void ClearScreen(void)
{
    unsigned int far *ptr=(unsigned int far *)0xb8000000;
    int i;

    for( i=0 ;i< 2000;i++)    ptr[i]=0x0720;
    gotoxy(1,1);
}


[ 本帖最后由 vopvcp 于 2012-10-29 15:06 编辑 ]
2012-10-29 15:04
快速回复:for循环语句中嵌套if语句 问题~~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011977 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved