标签: while-loop

为什么不递增z?

我想在C中编写一个简单的状态机执行器.我有这样的代码:

while(1) {  
  strcpy(fsm.state[x][z], lines[i]);
  printf("%i %i\n", x, z);
  z++; i++;
  if(strcmp(lines[i], ".") == 0) x++; z = 0;
  if(strcmp(lines[i], "") == 0) break;
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,如果ž应该只将其复位当前行,我从读线阵列等于"",这发生在我的测试情况下,每个第三次出现,这ž保持等于0,即使在X每隔三行成功递增一次.

我需要这样的输出:

1 0 \n 1 1 \n 1 2 \n 2 0 \n 2 1 \n 2 2 \n 3 0 \n 3 1等...

相反,我得到:

1 0 \n 1 0 \n 1 0 \n 2 0 \n 2 0 \n 2 0 \n 3 0 \n …

c matrix while-loop

0
推荐指数
2
解决办法
116
查看次数

Java如何在没有100%CPU负载的情况下持续监控某些内容?

我可以将while循环与wait()和notify()/ notifyall()一起使用吗?

编辑:我希望waitfornextprice方法的else条件只对putPrice方法执行.

public synchronized void putPrice(String s,int i) {
     if (getPrice(s) != i){
         this.Prices.put(s, i);
         notify();
     } 
}

public synchronized int waitForNextPrice(String s) {
    int b = null;
    if (hasPriceChanged(s)==true){
        b = getPrice(s);
    }
    else{
        //Need to block here, until putPrice() is called again
        while(hasPriceChanged(s)==false) wait();

        //Once putPrice has been called, b = getPrice();
        b = getPrice(s);
    }
    return b;
}
Run Code Online (Sandbox Code Playgroud)

java monitor while-loop wait

0
推荐指数
1
解决办法
653
查看次数

PHP循环查询,第一行

我正在尝试输出第一行的特殊内容,但它似乎在每一行输出,这里是我使用的代码:

$query = mysql_query("SELECT * FROM chat WHERE id > '".$_GET["latest"]."' ORDER BY id DESC LIMIT 0, 20");
$number = mysql_num_rows($query);
$i = 1;
while ($row = mysql_fetch_assoc($query)) {

echo "<div class='babble' style='width:130px;overflow:hidden;margin:auto;'><a href=\"javascript:ajaxpage('user_profile.php?game=1&ajax=1&user=".$row['author']."', 'content');\" style=\"cursor:pointer;\"><font color=#ff4355><b>".$row['author']."</b></font></a><font color=#ff4355>:</font></b> ".$row['babble']."</div>";
   if($i = 1)
   {
       echo "<script type='text/javascript'>newestid=".$row['id']."</script>";
$i = 2;
    }
}
Run Code Online (Sandbox Code Playgroud)

php mysql while-loop

0
推荐指数
1
解决办法
2436
查看次数

PHP上次循环

我有一个代码:

<?php $loop = some array with posts;
      while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <div class="class">
                <p>(data)</p>
             </div>   
     <?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)

现在我想要为最后一个循环更改div类(从"class"到"class2").怎么做?

例:

当"一些有帖子的数组"现在有4条记录时,我得到:

<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
Run Code Online (Sandbox Code Playgroud)

我想得到:

<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class"><p>data</p></div>
<div class="class2"><p>data</p></div> <!-- this one is different -->
Run Code Online (Sandbox Code Playgroud)

无论有多少阵列元素,我都在寻找能够工作的东西.

坦克!

php wordpress while-loop

0
推荐指数
1
解决办法
7801
查看次数

如何在MySQL中循环使用PHP循环?

表 persons

name  |   details
------------------
mathew| tax,home,car,insurance
john  | job,tax,employ
neil  | tax,home,car,job
yancy | consultant,rent,family
lucy  | home,car,insurance
Run Code Online (Sandbox Code Playgroud)

我希望循环遍历此表并搜索详细信息,然后将结果保存到另一个名为的表中 persons1

name  |   names
------------------
mathew| neil,lucy,john
neil  | mathew,lucy,john
john  | mathew,lucy,neil
Run Code Online (Sandbox Code Playgroud)

到目前为止,我编写了类似下面但不起作用的内容

mysql_connect("localhost", "root", "pass"); 
mysql_select_db("database");
$query = "SELECT * FROM persons"; 
$result  = mysql_query($query); 
while($r = mysql_fetch_array($result)) 
{ 
    $exp = explode(",",$r["details"]);
    $sql = mysql_query('SELECT * FROM persons WHERE MATCH (tags) AGAINST ("+$exp[0]" "+$exp[1]" "+$exp[2]" IN BOOLEAN MODE)'); 
    $result = array(); 
    while($row = mysql_fetch_assoc($sql))
    {   
        array_push($result,$row['name']);
        $name …
Run Code Online (Sandbox Code Playgroud)

php mysql while-loop

0
推荐指数
1
解决办法
257
查看次数

无限循环?

我在这个论坛上遇到过这个问题

#include <iostream>

using namespace std;

int main(int argc, char** argv) {

    int x=0;
    while (x<3) {
        x = x++;
        cout << x << endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

鉴于上面的代码,为什么while循环无限?在mac os下使用gcc 4.4,while循环确实终止:)所以这个问题并不适用于所有架构.我变得艰难的输出是
1
2
3

我没有看到0,我猜原因与双重任务有关?

c++ infinite-loop while-loop

0
推荐指数
1
解决办法
700
查看次数

里面的计算没有正常工作

在while while循环中,计算年平均值和年平均低温平均温度和年平均温度的计算不正常.

while (inFile.hasNext()) {
    //extract Month name from file
    month = inFile.next();
    //Remove comma for better presentation
    String   formatMonth = month.replace(',', ' ');
    //calculate high temperature from text file
    highTemp  = inFile.nextDouble();
    //extract low temperature file from text file
    lowTemp = inFile.nextDouble();
    //Calculate averaget Temperature from values
    averageTemp = (highTemp + lowTemp)/2;
    //Calculate Range
    range = (highTemp - lowTemp);
    //Calculate low temperature
    minTemp = Math.min(minTemp, lowTemp);
    //Calculate high temperature
    maxTemp = Math.max(maxTemp, highTemp);
    //Sum up high temperatures
    highSum =+ …
Run Code Online (Sandbox Code Playgroud)

java while-loop do-while

0
推荐指数
1
解决办法
352
查看次数

而循环结束条件

这吓了我一跳.以下测试失败; 循环结束时,我的值为9,而不是8.你能解释一下吗?

import junit.framework.TestCase;

public class TestDoWhile extends TestCase {
    final int LIMIT = 8;

    public void testDoWhile() throws Exception {
        int i = 0;
        do {
        } while (i++ < LIMIT);
        assertEquals(LIMIT, i);
    }
}
Run Code Online (Sandbox Code Playgroud)

java while-loop

0
推荐指数
1
解决办法
1883
查看次数

使用if语句条件查看NULL用户输入并打印:"sometext ..."

Python的缩进,没有分号和括号,花了一些时间让我习惯......来自C++.这个,我肯定是一个简单的修复,但我似乎无法找到问题.非常感谢您的帮助.这就是我所拥有的.当我运行此代码时,它就像第二个'if'语句不存在一样.即使我注释掉第一个'if'语句,第二个'if'语句中的打印行也永远不会打印到屏幕上:

import re


while True:
   stringName = raw_input("Convert string to hex & ascii(type stop to quit): ").strip()
   if stringName == 'stop':
      break
   if stringName is None: print "You must enter some text to proceed!"

   print "Hex value: ", stringName.encode('hex')
   print "ASCII value: ", ', '.join(str(ord(c)) for c in stringName) 
Run Code Online (Sandbox Code Playgroud)

python if-statement while-loop

0
推荐指数
1
解决办法
8773
查看次数

虽然循环不工作!

using namespace std;

void reverse(char a[],int slen, int elen)
 {
     int start,end,temp;
     for(start=slen,end=elen;start<end;start++,end--)
            {
                temp=a[start];
                a[start]=a[end];
                a[end]=temp;
            }
 }

 void reverseall(char b[])
  {
      char a[15];
      int i,j,n=0,len;
      for(i=14,j=0;i>=0,j<15;i--,j++)
           a[j]=b[i];

      i=0;
      j=0;

      while(a[i]!='\0')
         {cout<<"h";
            n++;
            i++;
         }

      while(j!=n)
         {
            if(j!=0)
              j++;
            len=0;
            while(a[j]!= ' ' && a[j]!='\0')
             {
                len++;
                j++;
             }
            reverse(a,j-len,j-1);
         }

     for(i=0;i<n;i++)
        cout<<a[i];
  }
int main()
 {
     char b[20]="hi how are you";
     reverseall(b);
     return 0;
 }
Run Code Online (Sandbox Code Playgroud)

我修改了一个适当的反转工作程序 ,只添加了3行,而while循环现在不能正常工作.

 for(i=14,j=0;i>=0,j<15;i--,j++)
               a[j]=b[i];

          i=0;
          j=0;  
Run Code Online (Sandbox Code Playgroud)

这是程序的链接,我希望输出为"你是多么喜欢". …

c++ reverse while-loop

0
推荐指数
1
解决办法
394
查看次数

标签 统计

while-loop ×10

java ×3

php ×3

c++ ×2

mysql ×2

c ×1

do-while ×1

if-statement ×1

infinite-loop ×1

matrix ×1

monitor ×1

python ×1

reverse ×1

wait ×1

wordpress ×1