即时尝试修复此循环但仍然遇到错误.基本上我假装我有4只乌龟,因为我卖的每只乌龟都得到一枚硬币.一旦我到0,我想打印我有多少硬币.我得到的错误就是这个,
用作真值的赋值周围的错误括号:***[分]错误1
这是代码:
while (turtles > 0) {
turtles = turtles - 1;
coin++;
if (turtles = 0)
printf("Now you have %d coins\n", coin);
}
Run Code Online (Sandbox Code Playgroud) 我正在为Decimal和Binary基数系统之间的转换编写一个函数,这是我的原始代码:
void binary(int number)
{
vector<int> binary;
while (number == true)
{
binary.insert(binary.begin(), (number % 2) ? 1 : 0);
number /= 2;
}
for (int access = 0; access < binary.size(); access++)
cout << binary[access];
}
Run Code Online (Sandbox Code Playgroud)
然而,在我这样做之前它没有用:
while(number)
Run Code Online (Sandbox Code Playgroud)
怎么了?
while(number == true)
Run Code Online (Sandbox Code Playgroud)
这两种形式有什么区别?提前致谢.
c++ evaluation boolean-expression while-loop conditional-statements
我正在查看TimSort java代码: 在SourceLo函数的特定行676到739中的原始源代码.它(大致)有以下布局:
outer:
while (true) {
//Code here
break outer; //Code within a few if tests in the loop.
}
//Code here executes somehow.
Run Code Online (Sandbox Code Playgroud)
我很困惑这个函数如何停止运行,因为唯一的break语句转到外部块(然后应该回到while(true),并且没有return语句.
我的问题是,当我尝试排序184个或更多元素时,第747行正在执行并抛出异常,我想弄清楚如何解决它,任何帮助都将非常感激.
[注意]:这是部署在Android手机上的Java的collections.sort方法调用的函数.
我有以下代码,最终导致分段错误.
for (int a=0; a<inputFileList.size(); a++)
{
fileLines = readFile(inputFileList[a].c_str());
for (int i = 0; i < fileLines.size(); i++)
{
if (fileLines[i].find("text") != string::npos)
{
bool warnFound = false, errFound = false;
i++;
while (fileLines[i].find("message") == string::npos && i < fileLines.size())
{
if (fileLines[i].find("error") != string::npos)
errFound = true;
else if (fileLines[i].find("warning") != string::npos)
warnFound = true;
i++;
}
i--;
if (errFound)
errCtr++;
else if (warnFound)
warnCtr++;
else
okCtr++;
}
}
fileLines.clear();
}
Run Code Online (Sandbox Code Playgroud)
当我删除while循环时,我不再得到此错误.但我不知道这个循环有什么问题.
谢谢您的支持
我正在尝试编写一个简单的Javascript(jQuery)函数,该函数随机显示6个Div.可能的11个.代码排序,它会随机显示大约一半的Div,但它在4到8之间变化.
谁能告诉我哪里出错了?它似乎应该如此简单但我完全迷失了!
我的代码:
<div class="offer">Offer 1</div>
<div class="offer">Offer 2</div>
... snip
<div class="offer">Offer 11</div>
<script src="query.min.js" type="text/javascript"></script>
<script>
var changed = 0;
while (changed < 6) {
$('.offer').each(function(index) {
if (changed < 6) {
var showOrNot = Math.floor(Math.random() * 2);
if (showOrNot == 1) {
$(this).addClass('offershow');
changed += 1;
$(this).text(changed); //debugging looking for the current value of changed
}
}
})
}
</script>
Run Code Online (Sandbox Code Playgroud) 我的最后一个问题取得了如此成功,我决定再试一次.下面的bash循环设置为遍历文件并一遍又一遍地向ant发送消息,直到它遍历文件末尾.当我更改运行ant的命令以简单地回显命令(用于测试)时,它运行正常.当我删除"echo"和命令周围的引号时,它只运行一次脚本并优雅地退出循环.对我来说这似乎很明显,这与ant和退出状态有关,但我不明白为什么会让它退出循环而不是返回.顺便说一句,它总是返回零.
echo "Looping through database results and sending to ant..."
# This while loop runs through pendingtxs.result and funnels them to ant
while IFS=, read txid courseid instructorid
do
echo "Beginning substitution of $1 into file..."
sed -e "s/XXXXXXXXXX/$txid/" -e "s/YYYYYYYYYY/$courseid/" -e "s/ZZZZZZZZZZ/$instructorid/" createcourse_notif.template.xml >temp.xml
echo "Substitution complete."
echo "Sending the temp.xml to ant..."
/xncpkgs/ant/bin/ant sendMessage -Dsend.destination=SmsQueue -Dmessage.file=temp.xml
antReturnCode=$?
echo "ANT: Return code is: \""$antReturnCode"\""
echo "Ant is done"
echo "Adding the xml to log.txt for later analysis"
cat temp.xml …Run Code Online (Sandbox Code Playgroud) 这是代码现在的位置:
<ul>
<?php
while ($themes = $model->getAllThemes()) {
echo '<li>' . $themes->id . ' ' . $themes->title . '</li>';
}
?>
</ul>
Run Code Online (Sandbox Code Playgroud)
$ themes数组看起来像这样:
Array
(
[0] => Theme Object
(
[id] => 11
[title] => NewTheme
)
[1] => Theme Object
(
[id] => 12
[title] => FakeTheme
)
)
Run Code Online (Sandbox Code Playgroud)
当我测试它时,它几乎进入无限循环,所以我猜它不知道数组有多长?我试图避免必须计算数组中的项目,我对foreach循环语法非常粗略.
我正在尝试在do while循环中发送多个帖子,但结果未添加
<script type="text/javascript">
function action() {
var initval = 1;
var endval = 5;
do {
var action_string = 'txtuser=someone';
$.ajax({
type: "POST",
url: "http://localhost/js.php",
data: action_string,
success: function(result){
$('div#append_result').append(initval + ',<br/>');
}
});
initval++;
} while (initval <= endval);
}
</script>
Run Code Online (Sandbox Code Playgroud)
输出为:5,5,5,5,5,
我需要输出为:1,2,3,4,5,
我的脚本有问题.
我有这个:
<?php
$r=mysql_query("SELECT * FROM memberships WHERE id!='".$userdata['membership']."'");
while($md = mysql_fetch_assoc($r)):
echo '<td class="header">'.$md['name'].'</td>';
endwhile;
?>
Run Code Online (Sandbox Code Playgroud)
这样可行.但如果在页面的下方,我会添加:
<?php
while($md = mysql_fetch_assoc($r)):
echo '<td class="result">'.$md['number_of_ads'].'</td>';
endwhile;
?>
Run Code Online (Sandbox Code Playgroud)
它不输出任何东西.为什么?
那么,当线程启动时,这段代码如何退出while语句?(请不要考虑缩进)
class ThreadUrl(threading.Thread):
"""Threaded Url Grab"""
def __init__(self, queue, out_queue):
threading.Thread.__init__(self)
self.queue = queue
self.out_queue = out_queue
def run(self):
while True:
#grabs host from queue
host = self.queue.get()
#grabs urls of hosts and then grabs chunk of webpage
url = urllib2.urlopen(host)
chunk = url.read()
#place chunk into out queue
self.out_queue.put(chunk)
#signals to queue job is done
self.queue.task_done()
Run Code Online (Sandbox Code Playgroud)
**编辑*
启动线程的代码:
def main():
#spawn a pool of threads, and pass them queue instance
for i in range(5):
t = ThreadUrl(queue)
t.setDaemon(True) …Run Code Online (Sandbox Code Playgroud)