代码的这一部分为客户端提供了一个ID,通过检查ID是否已被使用来检查下一个最高ID.由于某种原因,这导致了一个永无止境的循环为什么会这样?
int IDcounter = 0;
bool IDfound = false;
bool IDused = false;
while (!IDfound)
{
Console.WriteLine("Current ID check " + IDcounter);
Console.WriteLine("Number of clients " + clientList.Count);
foreach (Client id in clientList)
{
if (id.ID == IDcounter)
{
IDused = true;
IDcounter++;
break;
}
}
if (!IDused)
{
client.ID = IDcounter;
IDfound = true;
}
}
clientList.Add(client);
Run Code Online (Sandbox Code Playgroud) 我编写了下面的代码,我期待的是,当第一个循环结束并且不返回False时,流程将跟随第二个while循环.但是,流会跳过第二个while循环,只返回True.这是为什么?如何解决这个问题,使第一个while循环后的流程进入第二个while循环?
square = [[1,2,3,4],[4,3,1,4],[3,1,2,4],[2,4,4,3]]
# this is an auxiliary function
def getSum(lis):
sum = 0
for e in lis:
sum = sum + e
return sum
# here is where the problem is
def check_game(square):
standardSum = getSum(range(1, len(square)+1))
while square: #this is the first while loop
row = square.pop()
print row, 'row', 'sum of row=', getSum(row)
if standardSum != getSum(row):
return False
m = 0
while m < len(square): # the second while loop, which the flow skips
n …Run Code Online (Sandbox Code Playgroud) 所以我试图从while循环创建一组目录.文件创建部分的代码如下:
File userDIR=new File("Folder1//"+VARIABLENUMBER+"//"+VARIABLENUMBER+"_Single.txt");
boolean exists = userDIR.exists();
System.out.println(userDIR);//prints correct location
if (!exists) {
System.out.println("does not exist");
userDIR.mkdir();//THIS IS NOT HAPPENING
System.out.println(userDIR.mkdir());//Prints FALSE?
}else{
System.out.println("File Found");
}
Run Code Online (Sandbox Code Playgroud)
如果文件夹路径已经存在,它说它确实...但如果我尝试创建一个 - 它不起作用(只是跳过一种)或说错误......?
无法解决我做错了什么?
感谢您的任何意见或建议.
在某些情况下,我们可以互换使用while循环或do-while循环.我的一位朋友告诉我,这种情况我们应该使用do-while循环.因为它比同时更快.任何人都可以给我证明吗?
我正在尝试将表中的枚举移动到他们自己的表中,最简单的方法是运行一个SQL查询,我认为我可能会使用WHILE循环,但是在下面之前从未使用过的查询显然不起作用.是否可以执行以下操作:
WHILE (SET @cat = (SELECT DISTINCT `category` FROM `tablename`))
DO
BEGIN
INSERT INTO `categories` (title) VALUES (@cat);
END;
END WHILE;
Run Code Online (Sandbox Code Playgroud) 我只是在学习Java,在Deitel和Deitel的书"Java如何编程"中阅读教程,所以请原谅我正在犯的任何基本错误.我理解我的方法可能不是最好的,但我希望能够改进这一点.
我的问题是我相信我错误地构建了我的程序.执行程序时,正在输出IF和ELSE选项.
如果有人能告诉我为什么两个选项都在执行,那将非常感激
困境
package controlStatments;
import java.util.Scanner;
public class Review_4_20
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
//Declare Variables
double employeeOneRate;
double employeeOneHours;
double employeeTwoRate;
double employeeTwoHours;
double employeeThreeRate;
double employeeThreeHours;
int calculator;
double employeeOneTotalPay;
double employeeOneNormalPay;
double employeeOneTotalPayOverTime;
double overTimeRate;
//Initiate Variables
employeeOneRate = 0;
employeeOneHours = 0;
employeeTwoRate = 0;
employeeTwoHours = 0;
employeeThreeRate = 0;
employeeThreeHours = 0;
calculator = 0;
employeeOneTotalPay = 0;
employeeOneTotalPayOverTime = 0;
overTimeRate = 1.5;
employeeOneNormalPay …Run Code Online (Sandbox Code Playgroud) int i = 0;
int x = 10;
List<int> group = new List<int>();
while (i < x)
{
RichTextBoxShowTafel.AppendText(Convert.ToString(group[i]));
i++;
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?我想显示List的前10个数字:"group".
编辑:我实际上想要创建变量并连续打印...
我是新手,我认为我的if-else结构存在一些问题,但我无法理解问题实际上是什么.
我正在尝试执行以下操作:
<?php
$num = 1;
while($num <=10)
{
if ($num < 4)
{
print $num . " is less than 4 /";
}
elseif ($num = 4)
{
print $num . " is just 4 /";
}
elseif (($num > 4) && ($num < 10))
{
print $num . " is more than 4 and less than 10 /";
}
elseif ($num = 10)
{
print $num . " is just 10 /";
}
$num++;
}
Run Code Online (Sandbox Code Playgroud)
?>
我有几个小时左右,所以我终于决定问.任何帮助将不胜感激!Ty提前阅读.
快速问题;
$sql = mysql_query("SELECT * FROM cronjobs WHERE status = 0 ");
while($cronjob = mysql_fetch_array($sql)){
if($cronjob['suid'] != $cronjob['cuid']){
//echo 'not equal<br>';
$set = 0;
$sid = $cronjob['sid'];
$suid = $cronjob['suid'];
$cuid = $cronjob['cuid'];
$set = notify($sid, $suid, $cuid);
if($set==1){
//echo 'notified<br>';
$sql = "UPDATE cronjobs SET status = '1' WHERE id='".$cronjob['id']."'";
if(mysql_query($sql)){
echo '1<br>';
$set = 0;
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
notify()将return 1(数字)
问题是即使有更多记录,也只执行while循环的一次迭代.我不知道这里有什么问题.帮帮我吧.
我正在尝试创建一个bash脚本,以便在位于多个目录中的日志中轻松执行搜索.下面是我的do-while循环函数,它是发生错误的地方.如果需要完整的shell脚本进行故障排除,请告诉我."x"代表私人材料.
main_menu ()
{
TEMP=1
while [ "$TEMP" ! = "0" ]
do
clear
echo "###############################################"
echo
echo " xxxxxxxxxx xxx Search "
echo
echo "###############################################"
echo
echo " [1.] Search Logs by x/x "
echo
echo " [0.] Exit "
echo
echo " Select an Option: "
echo
read TEMP
case $TEMP in
1)
x_name
x_or_x
get_x
Run Code Online (Sandbox Code Playgroud)