我有一个SQL查询,应该提取一条记录并将其连接成一个字符串,然后输出该字符串。查询的重要部分如下。
DECLARE @counter int;
SET @counter = 1;
DECLARE @tempID varchar(50);
SET @tempID = '';
DECLARE @tempCat varchar(255);
SET @tempCat = '';
DECLARE @tempCatString varchar(5000);
SET @tempCatString = '';
WHILE @counter <= @tempCount
BEGIN
SET @tempID = (
SELECT [Val]
FROM #vals
WHERE [ID] = @counter);
SET @tempCat = (SELECT [Description] FROM [Categories] WHERE [ID] = @tempID);
print @tempCat;
SET @tempCatString = @tempCatString + '<br/>' + @tempCat;
SET @counter = @counter + 1;
END
Run Code Online (Sandbox Code Playgroud)
脚本运行时,@tempCatString输出为null,而@tempCat始终正确输出。是否有某些原因导致串联在While循环内不起作用?这似乎是错误的,因为增量@counter …
我写了一个脚本来对某些点进行地理编码,这些点的结构基本上是这样的:
//get an unupdated record
$arr_record;
while(count($arr_record) > 0)
{
//strings are derived from $arr_record
geocode($string1);
geocode($string2);
geocode($string3);
array_pop($arr_record);
}
function geocode($string) {
//if successful
update($coords)
}
function update($coords) {
//update the database
header('Location:http://localhost/thisfile.php')
}
Run Code Online (Sandbox Code Playgroud)
麻烦的是,即使地理编码成功并且数据库已更新,并且标题重新发送,脚本仍会返回到while循环而不重新加载页面并重新开始新记录.
这是PHP的正常行为吗?我该如何避免它像这样?
我确定有一个更好的方法来做到这一点,但我是新手,所以我做了它唯一的方法,我可以搞清楚.问题是,我有一个脚本,用RSS源中的最新帖子更新文本文件(我从你们那里得到了一些帮助来弄明白).但我想让这个脚本自动化,所以我做了这个:
import time
import os
seconds = 3600
kjor = 'python vg.py'
time.sleep(seconds)
os.system(kjor)
time.sleep(seconds)
os.system(kjor)
time.sleep(seconds)
os.system(kjor)
Run Code Online (Sandbox Code Playgroud)
我继续将那些24x向下复制.我知道这可以通过一些循环(虽然?)可以做得更好,但我害怕我在那个领域还没有很多知识(还).
然而,我的问题如下:如果我让这个系统运行更长时间,系统是否会受到任何损坏?
VB.net中while循环中允许的最大执行次数是多少?意思是,它检查变量是否等于某个值,但该值永远不会出现?在退出之前它会执行多少次代码?有没有办法设置最大执行次数而不以编程方式终止它?
谢谢您的帮助.
如何将以下while循环转换为PHP中的for -loop?
while( $row2 = pg_fetch_row( $result_tags )
Run Code Online (Sandbox Code Playgroud)
虽然-loops是我的错误来源.我看到while -loop如下.
for ( $i = 0 ; $i < count(pg_fetch_row( $result_tags )) ; $i++ )
Run Code Online (Sandbox Code Playgroud) 我试图想一个程序来计算Python中单词中不同字符的数量.
例如:
鉴于输入:
('Banana')
Run Code Online (Sandbox Code Playgroud)预期产量:
3
Run Code Online (Sandbox Code Playgroud)如何使用whileor for循环来执行此操作?
谢谢
不确定问题是否正确,但这是我想要完成的.
我正在运行一个for循环,我想在每个循环中更改if语句.
这是一个例子:
for(int i=0;i<3;i++){
int currentField = field;
var context1=currentField;
int curprogr=0;
switch (i){
case 0:
context1 = currentField % 10 != 0;
curprogr = 1;
break;
case 1:
context1 = Mathf.Floor(currentField/10) != 0;
curprogr = 10;
break;
case 2:
context1 = currentField % 10 != 0 && Mathf.Floor(currentField/10) != 0;
curprogr = 11;
break;
}
while(context1){ // Here is where I want it to chnage for each time the loop runs through //
// Some logic here... // …Run Code Online (Sandbox Code Playgroud) 下面的Java方法是指以打印数i由nLoopsPerSecond每秒次seconds秒:
public void test(int nLoopsPerSecond, int seconds) {
double secondsPerLoop = 1.0/(double)nLoopsPerSecond;
long startTime = System.currentTimeMillis();
long currentTime;
int i = 0;
while ((currentTime = System.currentTimeMillis()) < startTime + seconds*1000) {
System.out.println(i++);
while (System.currentTimeMillis() < currentTime + secondsPerLoop*1000);
}
}
Run Code Online (Sandbox Code Playgroud)
通过以下电话:
test(1000,1);
Run Code Online (Sandbox Code Playgroud)
我希望这种方法可以做System.out.println(i++);1000次,但我只有63次.
当我尝试使用此代码查看每个循环实际使用的秒数
public void test(int nLoopsPerSecond, int seconds) {
double secondsPerLoop = 1.0/(double)nLoopsPerSecond;
long startTime = System.currentTimeMillis();
long currentTime;
int i = 0;
while ((currentTime = System.currentTimeMillis()) < startTime + …Run Code Online (Sandbox Code Playgroud) 我正在构建一个程序,用多个小方块填充空心立方体.然后,通过随机立方体建立连接路径.通过查看每个多维数据集的直接邻居逐步找到该路径,并选择其中任何一个作为下一步.为了说明,下图显示了由立方体(红色立方体)组成的路径,
为了构建路径我开始形成一些立方体,用红色着色,找到它的邻居立方体(6个邻居,因为我们有6个面),随机选择任何一个,用红色着色选定的一个,然后通过重复相同找到它的邻居处理.这种方法很好,但如果邻居立方体已经是红色(已经属于路径),它将无法识别它并且可以再次选择它.要解决这个问题,我做了以下工作,
1-我创建了一个名为visited的数组,并将任何访问过的多维数据集的索引存储在其中.
2-我所存储的当前的立方体的邻居另一个数组称为一个比较它与访问之一,我删除的任何共同的元件,然后把残留在元件的随机数一个.
3-有时可以访问所有邻居,因此a将变为空.在这种情况下,我寻找任何当前的立方体,随机选择它们中的任何一个,检查其邻居,将它们存储在邻居数组(a)中并将其与访问的立方体数组进行比较.如果邻居数组不为空,这将继续重复(while循环).但就我而言,程序陷入了while循环.此外,有时它不会卡住,但路径中的立方体数量会少于指定的数量.
我已经获得了构建主立方体的代码,用小立方体填充它,并在之前的问题中通过Hoki获取邻居(在MATLAB中用小立方体填充立方体的整个体积)我刚刚添加了构建路径的机制使用邻居.这是代码,
%%
clf; figure(1); format compact
h(1) = axes('Position',[0.2 0.2 0.6 0.6]);
%These are the different 8 vertices of the cube, each is defined by its 3 x y z coordinates:
vert = [ 1 1 -1; -1 1 -1; -1 1 1; 1 1 1; -1 -1 1; 1 -1 1; 1 -1 -1; -1 -1 -1];
%These are the …Run Code Online (Sandbox Code Playgroud) 所以我在做while循环,我发现了一些奇怪的东西.
count = 0
while count <= 5:
count += 1
print(count)
Run Code Online (Sandbox Code Playgroud)
输出:
1
2
3
4
5
6
Run Code Online (Sandbox Code Playgroud)
这不是我不理解循环.这是怎么计数打印到六个?什么时候打印count只要count小于或等于5?
而且6是超过5.为什么会这样?
我知道我能做到
count = 0
while count != 5:
count += 1
print(count)
Run Code Online (Sandbox Code Playgroud)
但我只是想明白为什么推杆<=表现得很奇怪?
while-loop ×10
for-loop ×3
python ×3
php ×2
3d ×1
c# ×1
counting ×1
geocoding ×1
header ×1
if-statement ×1
java ×1
loops ×1
matlab ×1
python-3.x ×1
sql ×1
sql-server ×1
time ×1
vb.net ×1