我在TCL编程方面相当新,通过基础知识我遇到了以下代码片段:
set x 0;
while "$x < 3" {
set x [expr $x + 1]
if {$x >6} break;
if "$x > 2" continue;
puts "x is $x";
}
puts "exited second loop with X equal to $x\n"
Run Code Online (Sandbox Code Playgroud)
执行时,结果如下:
x是1
x是2个
退出的第二个循环,X等于7
令我惊讶的是,当执行continue命令时,似乎没有评估while循环测试(x <3).但是在tcl联机帮助页中声明" 正文中的continue语句将停止代码的执行,并且将重新评估测试. "
我错过了什么?
我想简单地使用带有php的while循环显示一些内容,但它无法正常工作.
这是代码 -
<?php
mysqli_select_db($connect,"users");
$select_title = "select title, message from messages where user = '$u' LIMIT 4 ";
$querying = mysqli_query($connect,$select_title) or die ('Whops! Something went wrong.');
$line = mysqli_fetch_assoc($querying);
//$title = mysqli_real_escape_string($connect,trim($line['title']));
while(($rows = mysqli_fetch_assoc($querying)))
{
echo $rows['title'];
}
Run Code Online (Sandbox Code Playgroud)
?>
现在我有两个标题,但只显示了一个.为什么这样?
boolean z = false;
do {
try {
a = sc.nextInt();
z = true;
}
catch(Exception e) {
}
}
while(!z);
Run Code Online (Sandbox Code Playgroud)
试试这个.如果在第一次正确执行时尝试整数.但是,如果输入错误的文本类型,即使您输入int next并跳过将布尔值赋值为true,它也会变为无限循环.为什么是这样?
我想将此for循环更改为while语句:
for (int x = 0; x < items.size(); x++) {...}
Run Code Online (Sandbox Code Playgroud)
我试过了:
int x = 0;
while(x<items.size()){
x++;
...
}
Run Code Online (Sandbox Code Playgroud)
但它不会起作用.
SELECT COUNT(*) INTO @count FROM `tableName` WHERE `id` = OLD.id;
WHILE @count > -1 DO
SET @count = @count - 1;
/* loop logic in here */
END WHILE;
Run Code Online (Sandbox Code Playgroud)
我有这个SQL,但是当我运行它时,我得到一个错误(SQL语法),MySQL说它接近WHILE @count > -1 DO SET @count = @count - 1;.我已经尝试在一个BEGIN ... END;区块中包裹,但这根本不会影响它.
由于MySQL出色的模糊错误,我无法弄清楚我做错了什么.
我确信这很简单但是已经很晚了,我无法发现它的生命.
我正在尝试用Python创建一个简单的冒险游戏.我已经到了需要询问用户是否希望选择选项A或B并使用while循环来尝试执行此操作的点:
AB = input("A or B?")
while AB != "A" or "a" or "B" or "b":
input("Choose either A or B")
if AB == "A" or "a":
print("A")
elif AB == "B" or "b":
print("B")
Run Code Online (Sandbox Code Playgroud)
问题是,无论你输入什么,都会出现"选择A或B"的问题.我究竟做错了什么?
这里的JavaScript代码是什么,特别是while循环:
function setAjaxLinks(){
var links = document.body.getElementsByTagName("a");
var linkL = links.length;
while (linkL--) {
if (!links[linkL].href.match('#')) {
mj.pageLoad(links[linkL]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道"mj"并不意味着什么,但一般的要点是什么?
我有一个像这样的数组:
Dim classes() as String = {"FR%", "SO", "JR", "SR", "SR5"}
Run Code Online (Sandbox Code Playgroud)
我需要像这样遍历这些值:
For Each value as String in classes
Next
Run Code Online (Sandbox Code Playgroud)
问题是,我在For Each..Next里面有一个If..Then..Else子句,它说的是:
If actual_class = value Then
txt.Text = "Welcome"
Else
txt.Text = "Goodbye"
Run Code Online (Sandbox Code Playgroud)
当我运行它时,除非个体是字符串数组中的最后一个值("SR5"),否则它们将获得消息"Goodbye"...所以,我需要以某种方式迭代遍历每个值,就像使用a对于Every..Next循环,但是一旦它击中了学生的类,就像Do..While循环一样突破循环 - 这样它们的值就不会被Else子句超越.
我正在通过艰难的方式学习python,并在练习33中获得额外的功劳2我试图利用其中一个raw_input或argv设置一个将在while循环中使用的变量:
# from sys import argv
# script, my_num = argv
def all_the_numbers(n):
"""increment by 1 up to limit n"""
i = 0
numbers = []
while i < n:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
# print "Please enter an integer: "
# n = raw_input("#")
# n = my_num …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用bash读取文件的一部分并停止和特定行.我对bash不是很熟悉,但我一直在阅读手册和各种参考资料,我不明白为什么类似下面的东西不起作用(但会产生语法错误):
while { read -u 4 line } && (test "$line" != "$header_line")
do
echo in loop, line=$line
done
Run Code Online (Sandbox Code Playgroud)
我想我可以写一个测试"完成"变量的循环,然后在循环中进行我的实际测试并适当地设置"完成",但我很好奇1)为什么以上不起作用,2)是有一些小的修正可以使它工作?我仍然相当困惑何时使用[,(,{,或((因此,或许其他一些组合可能会起作用,尽管我已尝试了几种.
(注意:当我在循环上面调用它时,"read -u 4 line"工作正常.我在文件描述符4上打开了一个文件.)