标签: while-loop

直到var不为null

编辑几年:在我开始使用C#/ .NET时,这显然是一种可怕的方法.希望这个问题有助于另一个具有相同"问题"的菜鸟.

这是处理这种情况的最佳方式吗?

while(true)
{
    if(Main.ActiveForm != null)
    {
        Main.ActiveForm.Invoke(new MethodInvoker(Main.SomeMethod));
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是在第二个线程上执行的.

.net c# while-loop

-1
推荐指数
2
解决办法
4779
查看次数

如何让程序确定输入是否是python中的int?

下午好.我正在尝试创建一个程序来打印数字描述.我是非常基本的python,我有点卡在这个特殊的问题上.任何人都可以告诉我如何让程序区分数字继续程序,Q,再见或回车结束声明?

while True:

    N = eval(input("Enter an input: number to continue, Q, bye or carriage return to quit")

    if N == int

        N => 0 print("positive")

        else print("negative")
Run Code Online (Sandbox Code Playgroud)

python while-loop

-1
推荐指数
1
解决办法
72
查看次数

在while循环中设置条件

我有以下C#源代码:

public static bool PeulaRashit()
{
    int days;
    double totalPayForService;

    Console.WriteLine("Enter number of days");
    days = int.Parse(Console.ReadLine()); 
    if (days== 999)
        return false;
    totalPayForService = TotalService(days);
    TotalPyament(totalPayForService, days);
    return true;
}

static void Main(string[] args)
{
    while (.....) //what should I do here?
    {}
}
Run Code Online (Sandbox Code Playgroud)

我想要PeulaRashit重复该方法,直到它false.我的问题是它应该是什么条件while才会发生?

c# while-loop

-1
推荐指数
1
解决办法
114
查看次数

Python,字符串输出"无"?

我循环一个字符串并在ASCII值中加1,但最后,这个"无"弹出.它是什么?

str_numbers = input ('> ')

i=0

while i <len(str_numbers):
    x = print(chr(ord(str_numbers[i]) + 1), end="")
    i=i+1

print (x)
Run Code Online (Sandbox Code Playgroud)

样本输出:

ABCDEF

bcdefgNone

python string ascii while-loop

-1
推荐指数
1
解决办法
62
查看次数

如何在while循环中填充数组列表

我的问题是这个

Scanner sf = new Scanner(f);
ArrayList<String> teamArr = new ArrayList<String>();
int counterPopulate = 0;

while(sf.hasNextLine()){
    teamArr[counterPopulate] = sf.nextLine();
    counterPopulate++;           
}
Run Code Online (Sandbox Code Playgroud)

任何解决方案,这是一个尝试捕获包围.在这一部分得到问题teamArr[counterPopulate] = sf.nextLine();

java arraylist while-loop

-1
推荐指数
1
解决办法
4294
查看次数

做的同时永远循环

我遇到了这种方法的问题,我永远坚持"抱歉你必须指定一个Deeppan或瘦基地,再试一次:"即使我输入jimmy,harry,deeppan,thin,Thin ..等我输入之后deeppan或thin,我希望String存储在变量"size"中并返回

我缺少什么想法?

 public String Input(){


    String size;

    Scanner sc = new Scanner(System.in);
    System.out.println("thin or thick: ");

    do {
        size = scan.next();
        if ( !size.equalsIgnoreCase( "thick") || !size.equalsIgnoreCase( "thin" )) {
            System.out.print("Sorry you must specify a thick or thin base, try again: ");
        } else {
            break;
        }
    } while ( true );

    return size;
} 
Run Code Online (Sandbox Code Playgroud)

java while-loop do-while

-1
推荐指数
2
解决办法
147
查看次数

双重条件而已

以下语句在Java中的含义是什么?

while(condition_1) {
    do something...
} while (condition_2);
Run Code Online (Sandbox Code Playgroud)

有没有真实的情况可以使用它?

更新:代码示例

    int i = 3;
    while (i < 10) {
        System.out.println(i++);
    } while (i < 15);
Run Code Online (Sandbox Code Playgroud)

java while-loop java-7

-1
推荐指数
1
解决办法
154
查看次数

虽然循环没有退出

这方面是Java新手.我正在尝试运行一个滚动两个骰子的程序,当两个骰子之间的总滚动为7或11时,程序将退出.出于某种原因,我的while语句一遍又一遍地执行,我无法弄清楚原因.任何帮助将非常感激.代码如下.

再次,这是非常新的.不是那么专注于一种更有效的方式来实现这一点,而是关注为什么这不起作用的语义细节.

// import required packages for the program
// import all classes to be on the safe side
// will be using input/ouput and math, so those imports are needed
import java.io.*;
import java.math.*;
import java.text.*;

// Declare a class, class name Dice chosen
public class Dice
{
// need to use throws IOException because we are dealing with input and output, simple main method will not suffice
    public static void main(String[] args) throws IOException
    {

        // declare variables …
Run Code Online (Sandbox Code Playgroud)

java while-loop

-1
推荐指数
1
解决办法
794
查看次数

未终止的语句适用于Java

对于CS类,我必须打印2的所有权力n.我编写了以下代码,其中我故意在循环内的语句末尾省略了分号.为什么这样做?在C++中你会得到一个令人讨厌的错误.您能否提供编译器尝试执行的操作的技术说明?

int n = 100;

int a = 0;
while (Math.pow(2, a++) < n) {
    System.out.println(Math.pow(2, a))
}
Run Code Online (Sandbox Code Playgroud)

发生这种情况的IDE是NetBeans.

NetBeans显示它无法编译(它变为红色),但无论如何它都会运行.有人可以解释一下,使用JVM,为什么会发生这种情况?

java netbeans while-loop

-1
推荐指数
1
解决办法
259
查看次数

为什么这个while语句的"或"部分不起作用,但是break语句呢?(对于C)

学习编码,并尝试一个简单的while循环数字猜谜游戏.这个想法是,如果错误猜测的数量达到5,就会导致循环变为"假"并结束.相反,它将循环,直到它被测试站点作为无限循环结束."破解"版本的工作正常.我的问题是为什么if"break"工作,但是|| 设置值= false不起作用?

没有工作的代码片段

while (secret != guess || wrong < 5)
{
    if (guess < secret)
    {
        printf("You guessed too low\n");
        wrong++;
    }
    else 
    {
        printf("you guessed too high\n");
        wrong++;
    }
    printf("Input another guess\n");
    scanf ("%d", &guess);

}
Run Code Online (Sandbox Code Playgroud)

工作代码片段

while (secret != guess)
{
    if (guess < secret)
    {
        printf("You guessed too low\n");
    }
    else 
    {
        printf("you guessed too high\n");
    }
    printf("Input another guess\n");
    scanf("%d", &guess);
    wrong = wrong + 1;
    if (wrong >= 5)
    {
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

c while-loop

-1
推荐指数
1
解决办法
92
查看次数

标签 统计

while-loop ×10

java ×5

c# ×2

python ×2

.net ×1

arraylist ×1

ascii ×1

c ×1

do-while ×1

java-7 ×1

netbeans ×1

string ×1