我想在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 …
我可以将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) 我正在尝试输出第一行的特殊内容,但它似乎在每一行输出,这里是我使用的代码:
$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 $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)
无论有多少阵列元素,我都在寻找能够工作的东西.
坦克!
表 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) 我在这个论坛上遇到过这个问题
#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,我猜原因与双重任务有关?
在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) 这吓了我一跳.以下测试失败; 循环结束时,我的值为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) 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) 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)
这是程序的链接,我希望输出为"你是多么喜欢". …